Skip to content

feat: append a paragraph when clicking below the document - #230

Merged
Azganoth merged 1 commit into
mainfrom
feature/trailing-paragraph-click
Aug 15, 2026
Merged

feat: append a paragraph when clicking below the document#230
Azganoth merged 1 commit into
mainfrom
feature/trailing-paragraph-click

Conversation

@Azganoth

Copy link
Copy Markdown
Owner

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.

  • The editable area extends past the last block, so the gesture is recognized by a primary-button mousedown that lands on the editor element itself, below the last block's bounding box.
  • The insert runs during mousedown and 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.
  • An open Markdown source projection is finalized before the insert. A document-changing transaction that moves the selection out of a projection drops the session and leaves its source behind as literal text.

Related Issue

Not applicable.

Verification

src/features/editor/plugins/trailingParagraph.test.tsx covers 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.tsx now 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:

  1. Clicking the empty space below a document that ends with text appends an empty paragraph and places the caret in it, without the caret first landing in the last line.
  2. Pressing in that same space and dragging up over the document still starts a drag-selection.

Also verified in Chromium on Windows 11 with the editor mounted standalone against the dev server: document.caretPositionFromPoint at 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.ts is left as follow-up.

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.
@Azganoth Azganoth added the Feature New feature or request label Aug 15, 2026
@Azganoth Azganoth self-assigned this Aug 15, 2026
@Azganoth
Azganoth enabled auto-merge (squash) August 15, 2026 04:37
@Azganoth
Azganoth merged commit a61106a into main Aug 15, 2026
3 checks passed
@Azganoth
Azganoth deleted the feature/trailing-paragraph-click branch August 15, 2026 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant