Repository navigation
Keep spaces after the caret out of a new list item - #7
Merged
Merged
Conversation
Enter in a list item moved the spaces after the caret into the new item: "1. one‸ two" gave "2. ‸ two". The old editor trimmed them. The move to CodeMirror lost that, and no test noticed. CodeMirror's insertNewlineContinueMarkup drops the spaces before the caret, but not those after it. Enter now deletes those first, then lets CodeMirror continue the list or quote. Layers map through the two steps one at a time. So a ghost that began with a space moves into the new item, not over the line break. - An empty item with spaces after the caret now ends the list, as in the old editor. - A caret right after a marker, as in "1.‸ a", keeps the space that ends the marker. - keys.test.ts has every old list test, plus cases for quotes, tabs, a ghost at the caret, undo, and a selection. - The fix-bug skill no longer calls this bug open. Two old renumbering cases stay out of the tests for now. Today's editor follows CommonMark there and renumbers further than the old one did. That choice is open.
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.
Enter in a list item moved the spaces after the caret into the new item. The old editor trimmed them (asked for on 14 Oct). The move to CodeMirror lost that, and no test noticed: only 1 of the 8 old list tests was ported.
1. one‸ two1. one\n2. ‸ two1. one\n2. ‸two- one ‸ two- one\n- ‸ two- one\n- ‸two1. a‸1. a\n2. ‸1. a\n2. ‸> a‸ b> a\n> ‸ b> a\n> ‸bRoot cause
insertNewlineContinueMarkupCommandin@codemirror/lang-markdown6.5.2 trims spaces before the caret, then replaces only from there to the caret (dist/index.js, near line 270). Spaces after the caret stay, and land at the start of the new item.Fix
In
enter(src/editor/keys.ts), for lists and quotes:setLayers. A single replacement would leave a ghost that starts with a space (common for Lab cuts) on the old line, covering the line break.1. a\n2. ‸ends the list like1. a\n2. ‸.1.‸ a,- [ ]‸ a,>‸ a) keeps the space that ends the marker. These behave as on main..claude/skills/fix-bug/SKILL.mdno longer calls this bug open.Tests
src/editor/keys.test.tsgets an "Enter in a list" block. It ports the old list tests, except the two renumbering cases below. The old "drops an empty item in the middle" case was already in "continues a list and ends it on an empty item". New cases cover quotes, tabs, a ghost at the caret (with undo and redo, checking the saved Markdown), undo after typing, a selection, and a caret right after a marker.Verify
Review
review-changesran a task review, an editor-check review, and a tests-check review. A fresh review then checked the final diff. Fixed from their findings: the ghost moving across the line break, the empty item with a trailing space, the caret after a marker, and five test gaps. Not changed:Open questions for the owner
Renumbering past an indent change or a lazy line. Not decided yet, so these two old cases are not in the tests:
1. a‸\n 2. b\n3. cgives4. c. The old editor kept3. c.1. a‸\n - x\n2. b\nText\n3. cgives4. c. The old editor stopped atText.This PR doesn't change either one. Recommendation: keep CommonMark. The preview's parser puts
3. cin the same list in both cases. Renumbering keeps the numbers in the text consistent with how the list renders. The old stop came from the old editor reading lists line by line.Enter with a selection in a list item falls through to the default Enter, as on main.
- one «two» threegives- one \nthree: no new item, and a trailing space. The old editor gave- one\n- three. The test "leaves a selection to the default Enter" keeps main's behavior until you decide.CLAUDE.md says commands return a
TransactionSpec. Every command inkeys.tsdispatches instead, this one included. The rule or the file should change.Already on main, not changed here
- This{- really -}‸good.saves as- This{- really\n- -}good.- ‸ twogives-\n- ‸two.