Skip to content

Nest list items with Tab and Shift+Tab - #30

Open
jwahdatehagh wants to merge 1 commit into
omacom:masterfrom
jwahdatehagh:nested-lists
Open

Nest list items with Tab and Shift+Tab#30
jwahdatehagh wants to merge 1 commit into
omacom:masterfrom
jwahdatehagh:nested-lists

Conversation

@jwahdatehagh

Copy link
Copy Markdown

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 under 1. , more as the marker grows:

- one            1. one              1. one
- two|    →      2. two|      →      2. two
                                     3. three
- one            1. one              1. one
  - two|            1. two|             1. two
                 2. three            2. three
  • Tab nests the items the caret or selection touches under the item above them; Shift+Tab lifts them back beside their parent.
  • Children travel with the item they hang under, and a selection moves every item it touches while keeping their relative depth.
  • Ordered levels renumber once the structure changes. A level that already opened the same way keeps its first number — a list deliberately starting at 3. stays there — while a level the edit creates starts at 1.
  • Nothing to nest under (first item of a list), already outermost, or inside a fence: Tab is left to whatever it did before, so behaviour outside lists is untouched.

Return moved into the same library

smartReturn was building edits in QML from its own copy of the Markdown grammar, which had already drifted from the one used elsewhere (\s vs [ \t]). It now asks EditorMutations.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.qml keeps 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 real Tab/Shift+Tab key events into Main.qml and 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

  • One Tab takes two undo steps, since replaceRange() is a remove plus an insert. That is how the existing bold/italic/link mutations already behave — QML's TextEdit exposes no undo grouping — but Tab is pressed far more often, so it is more noticeable here.
  • Lines that move get space indentation even in a file that used tabs. Tab-indented input is read correctly (tab stops of 4); only the lines an edit rewrites are normalised.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant