Nest list items with Tab and Shift+Tab - #30
Open
jwahdatehagh wants to merge 1 commit into
Open
Conversation
Return already carried a list marker onto the next line, but Tab did nothing to the item it landed on, so nesting had to be spaced out by hand and ordered lists renumbered by hand after every move. Indent to where the parent item's own text starts rather than by a fixed unit, which is how a Markdown reader resolves nesting: two columns under `- `, three under `1. `, more as the marker grows. An item nests under the sibling above it, so the first item of a list has nothing to nest under and stays put, and outdenting lifts an item to sit beside the item it used to hang under. Children travel with the item they hang under, and a selection moves every item it touches while keeping their relative depth. Renumber each ordered level once the structure has changed. A level that already opened the same way keeps its first number, so a list deliberately starting at 3 stays there, while a level the edit creates starts at 1. Move the rest of Return's behaviour into the same library, which now answers with the edit to apply instead of leaving Main.qml to build one from a second copy of the Markdown grammar. Inserting into an ordered list renumbers what follows it, and an empty nested item steps out one level rather than ending the list outright.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Return already carried a list marker onto the next line, but Tab did nothing to the item it landed on, so nesting had to be spaced out by hand and ordered lists renumbered by hand after every move.
Indentation follows the marker, not a fixed unit
A nested item lines up with the text of the item it hangs under, which is how a Markdown reader resolves nesting — two columns under
-, three under1., more as the marker grows:3.stays there — while a level the edit creates starts at1.Return moved into the same library
smartReturnwas building edits in QML from its own copy of the Markdown grammar, which had already drifted from the one used elsewhere (\svs[ \t]). It now asksEditorMutations.returnPlan()for the edit to apply, so there is one definition of a list item. That also picks up two things the old path couldn't do: inserting into an ordered list renumbers what follows, and an empty nested item steps out one level instead of ending the list (the outermost level still drops out, as before).Blockquote continuation moved along with it, since it was the last thing keeping the second grammar alive.
Shape
The library takes a document and offsets and returns a plan — a range, its replacement, and where the caret lands — which the editor applies through the existing
replaceRange().Main.qmlkeeps key handling and editor state and no longer parses Markdown itself.Testing
./bin/test— three new cases covering the plan logic, Return, and one that sends realTab/Shift+Tabkey events intoMain.qmland checks the resulting text, so the key wiring is covered and not just the JS.Return was also diffed against its previous behaviour across 21 documents at every caret position: identical everywhere except where this change intends to differ (renumbering, the nested empty-item outdent, and carrying a marker's own spacing over on
- wide/> wide).Two things worth knowing
replaceRange()is a remove plus an insert. That is how the existing bold/italic/link mutations already behave — QML'sTextEditexposes no undo grouping — but Tab is pressed far more often, so it is more noticeable here.