Break one line, not two, when Return lands on a blank line - #12
Conversation
smartReturn ends a paragraph with two breaks because a new paragraph in this editor stands apart from the one above it by a blank line. A line that is already blank has no paragraph to stand apart from, so that second break was a gap nobody asked for: every Return on a blank line grew the space in twos, an empty document included. Fall back to a single break when there is nothing but whitespace on either side of the caret on its line. The list and code fence branches above already inserted one break each and are untouched. Fixes omacom-io#11 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TyQRJCyR76uk7XaNAB8jMC
The new branch reads the line around cursorPosition, but a selection is deleted before the break goes in, and dragged right to left it leaves the caret at the far end of it. Selecting "\ntw" in "one\n\ntwo" backwards therefore inserted one break where the identical selection made left to right inserted two: the caret's line was blank, but the line the break landed on was not. Read the prefix from the start of the selection and the remainder from its end, so the test describes the line that survives it either way. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Return followed by Backspace on a blank line now eats a paragraph break. In The helper collapses two breaks whenever they sit behind the caret, so with this change it can undo more than the Return that produced them. Telling the two apart wants both ends of the pair: a paragraph break is what Return inserts only when the line before the pair is not blank, and only when the caret's own line does not continue past it. That is verified, not sketched — with it, Return then Backspace on the blank line returns to I did push df2f992, for the other thing. The new branch reads the line around Everything above was checked by driving the real key handler in a window on a throwaway VM. The suite is 13 passing on |
Fixes #11.
smartReturnends a paragraph with two breaks, which is right for a paragraph: a new one stands apart from the one above it by a blank line, so Return at the end oftwocorrectly givestwo\n\n. A line that is already blank has no paragraph to stand apart from, so that second break was a gap nobody asked for — every Return on a blank line grew the space in twos, and an empty document opened with two blank lines rather than one.The fallback now inserts a single break when there is nothing but whitespace on either side of the caret on its line. The list-item and code-fence branches above it already inserted one break each and are untouched.
Test
breaksLinesOnReturndrives a real window with the keyboard, covering both the bug and the branches that must not move:one\n\ntwo(on the blank line)one\n\n\ntwoone\n\ntwo(on the blank line)one\n\n\n\ntwoone\n\ntwo(end oftwo)one\n\ntwo\n\n\none\n \ntwo(between the spaces)one\n \n \ntwo- item- item\n-, then- item\n\nmake && ./tst_omawriteinbuild-tests: 13 passed, 0 failed.🤖 Generated with Claude Code
https://claude.ai/code/session_01TyQRJCyR76uk7XaNAB8jMC