feat: append a paragraph when clicking below the document - #230
Merged
Conversation
Handling `mousedown` rather than a click, and leaving the event unhandled afterwards, lets the click place the caret once: the paragraph is already rendered under the pointer by the time the browser hit-tests it, and the drag-selection the gesture may become still starts normally. A projection left open elsewhere in the document is finalized first. A doc-changing transaction that moves the selection out of one drops the session and strands its Markdown source as literal text.
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.
Summary
Clicking the empty space below the document appended nothing and dropped the caret into the last line at whatever horizontal position the pointer happened to sit. It now appends an empty paragraph and puts the caret there, unless the document already ends with an empty paragraph.
mousedownthat lands on the editor element itself, below the last block's bounding box.mousedownand the event is then left unhandled. The new paragraph is rendered under the pointer before the browser hit-tests the click, so the caret is placed once, and the drag-selection the gesture may become still starts normally.Related Issue
Not applicable.
Verification
src/features/editor/plugins/trailingParagraph.test.tsxcovers the appended paragraph and caret placement after text and after a table, the finalized projection, the no-op when the document already ends with an empty paragraph, and the untouched click inside the last line.src/features/editor/plugins/doubleClickSelection.test.tsxnow dispatches its synthetic clicks on the rendered block instead of the editor element, which is where a real click on text lands.Manually verified in the desktop application on Windows 11:
Also verified in Chromium on Windows 11 with the editor mounted standalone against the dev server:
document.caretPositionFromPointat a point 265px below the last paragraph resolves inside that paragraph's text before the insert, and at offset 0 of the appended empty paragraph after it, which is the hit-test a real click's caret placement uses.Notes
The projection detail above is a latent defect independent of this change: any document-changing transaction dispatched while a projection is open, whose selection ends up outside it, abandons the projected source as literal text that saves escaped. Every current caller avoids it by finalizing first, as this plugin now does. Hardening that path in
sourceProjection.tsis left as follow-up.