[fix] fix tab insertion#6196
Conversation
|
The latest commit further changes |
|
I appreciate this, especially ensuring that YAML frontmatters won't contain tab characters anymore. However, I think we should spend at least a little bit on discussing the implementation, because — at least for me, personally — this PR would prove to be an unwanted change. To elaborate a bit:
If I understand you correctly, this would change the behavior so that, when one is somewhere within a line, this would no longer indent the line, but instead insert a literal tab character. This would be a regression, because I have grown accustomed to just clicking somewhere in a line to indent/unindent it. However, I fully understand and support workflows that rely on tabs instead of spaces, so I am more than happy to implement this, but with some changes. Thus, I have two refactoring requests:
Thank you! |
|
Sure, I can make it configurable. I think it should default to allowing inserting tabs/spaces in the text, since it would otherwise be a big change from previous Zettlr behavior, which currently allows inserting tabs. I don't think I should separate out the YAML logic, though. The YAML case would be an exact duplicate, except for the YAML check.
Just to clarify, this would only be a regression from the changes in #6168. Before that PR, Zettlr used the codemirror |
|
Another point -- there are three places in the code that could re-use the new
|
Oh god, I completely overlooked that, which might be due to me never wanting Tabs in my files, so I didn't realize this. So yes, your change is correct. Let me go through this again, because given the fact that it worked the last years without me complaining means it worked as intended. So no need to make this configurable. |
|
Ah I see you made it configurable already. Then let's keep that, it can't hurt, and this way your effort wasn't wasted! |
nathanlesage
left a comment
There was a problem hiding this comment.
Looks good, the only thing I wanted to change is the config variable to be more verbose; otherwise it may be difficult to see what it does. Other than that, this thing is ready to merge. You should be able to just go through the suggestions and apply them in order, I think!
Move any additional refactors to a new PR! Thanks!
| }, | ||
| { | ||
| type: 'checkbox', | ||
| label: trans('Always indent the current line when pressing Tab'), |
There was a problem hiding this comment.
| label: trans('Always indent the current line when pressing Tab'), | |
| label: trans('Always indent the current line when pressing Tab'), | |
| info: trans('Zettlr always indents list items. Turn this setting on to always indent any line and never insert Tab characters.'), |
There was a problem hiding this comment.
So this description is not entirely accurate, as it doesn't control whether tab characters are inserted or not, that would be controlled by the setting above, indentWithTab. It only determines whether pressing tab always indents the line, or if it inserts an indent unit at the cursor.
There was a problem hiding this comment.
Hmhm, I'll think about this and improve the wording later on. No need to worry about this detail at this point :)
Co-authored-by: Hendrik Erz <hendrik@zettlr.com>
Co-authored-by: Hendrik Erz <hendrik@zettlr.com>
Co-authored-by: Hendrik Erz <hendrik@zettlr.com>
Co-authored-by: Hendrik Erz <hendrik@zettlr.com>
Co-authored-by: Hendrik Erz <hendrik@zettlr.com>
Co-authored-by: Hendrik Erz <hendrik@zettlr.com>
Co-authored-by: Hendrik Erz <hendrik@zettlr.com>
Co-authored-by: Hendrik Erz <hendrik@zettlr.com>
|
Thank you! |
Description
This PR fixes tab insertion and improves YAML tab-to-space sanitation.
Closes #6190
Changes
The
codemirrorinsertTabcommand was reimplemented. The native command always inserts tabs (when not callingindentMore), so we need a custom implementation that inserts spaces or tabs. The functionality was separated from thelisthelper function. As a result, a new keybinding was added.The
YAMLFrontmattersanitation was improved. TheisInYamlFrontmatterfunction was moved to its own file and renamed toyamlInSelection, mirroring therangeInSelectionutility. In addition, if a selection is within a yaml node, theindentWithTabsconfig setting is overriden temporarily. This is necessary so thatindentMoreuses spaces when withinYAMLFrontmatternodes. Otherwise, we still get tab inserts.Finally, the
isListTouchedBySelectionwas refactored and renamed tolistInRangeto mirror the other similar functions. It was refactored to usetree.resolve()rather than iterate over the tree.Additional information
Tested on:
macOS 26