Repository navigation
fix(ui): reveal the caret after the composer's scripted edits - #5812
UncertaintyDeterminesYou4ndMe wants to merge 1 commit into
Conversation
hqhq1025
left a comment
There was a problem hiding this comment.
Reviewed exact head 1bcb969ad37eac9896e9adf166990138fdd5d37f. The three-file change adds a trailing-break class and CSS padding to reveal the composer caret without changing serialized drafts. The two issues below keep this head out of the merge candidate set: the original end-of-draft path still bypasses the compensation in a real Electron/Chromium window, and the current-head Storybook smoke fails on draft restoration.
Local Node 24 clean install, build:test, 38 focused composer/caret tests, focused Biome, ASF headers, diff-check, and merge-tree against current main passed. In the real Electron probe, 12 lines plus Shift+Enter left scrollTop at 0 with 74px available to scroll and no compensation class. Hosted test failed in the EmptyHome Storybook play assertion (expected 96 to be 74) after switching away from and back to a three-line draft; its isolated retry also failed. The four new linkedom tests model caret placement rather than exercising Chromium selection or CSS layout. I did not test macOS/Windows or the WorkHub compact layout. No schema or migration changes were found.
Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.
| const tail = range.cloneRange(); | ||
| tail.selectNodeContents(editable); | ||
| tail.setStart(range.startContainer, range.startOffset); | ||
| if (tail.toString() !== '') return; |
There was a problem hiding this comment.
[P2] The real end-of-draft Shift+Enter path still returns here. In an Electron/Chromium composer, insertLineBreak leaves the collapsed caret at offset 0 of the final "\n" text node, with one "\n" after the caret. Thus this range's toString() is "\n", not empty, and the function never adds the class or scrolls. With a 12-line draft I measured scrollTop=0, scrollHeight-clientHeight=74, and no class after Shift+Enter, so the original capped-editor defect remains. The new linkedom harness instead advances its synthetic caret past both inserted newlines (composer-shortcuts.test.tsx:252-253), making the test green without covering this browser path. Please exercise actual Chromium selection and the capped scroll case.
| } | ||
| caretPendingRef.current = false; | ||
| placeCaretAtEnd(editable); | ||
| // A restored draft can itself end in a newline (a pasted "abc\n" |
There was a problem hiding this comment.
[P2] This new compensation call on caret restore also regresses the existing EmptyHome lifecycle contract. On the current head, hosted Storybook smoke fails reproducibly (including its isolated retry) after a three-line draft is switched away and restored: editor.clientHeight becomes 96px instead of its pre-switch 74px, exactly one extra line. The only added layout path is the trailing-break class/padding, so the restore-time guard is treating a draft with a real final line as boxless. Keep the restored editor at its original height unless the caret truly needs a missing line box; the required test check is red on this head.
1bcb969 to
1ff5612
Compare
|
Rewritten as
The fix now scrolls the caret into view after the Shift/Alt+Enter break, the multi-line insert seam and the plain-text paste, covering the bottom-row mid-line break as well. |
Review summaryThe rewritten head ( I see two merge-blocking concerns:
The old automated review comments were against the pre-rewrite head and should not be treated as current findings. CI for the current head is green, but I would not sign off until the browser-level coverage and nested-DOM behavior above are resolved. |
1ff5612 to
47fff77
Compare
|
Thanks — both addressed in Browser-level coverage. Added
The oracle is independent of the helper: the caret's line is counted from the DOM text before the selection, and the assertion is that its line box lies inside Nested caret. |
There was a problem hiding this comment.
Reviewed commit 47fff77. The revised caret-reveal logic addresses the earlier Shift+Enter failure in the exercised paths, and the previous draft-height regression is absent: the two new real-Chromium Storybook scenarios and EmptyHome pass locally. The 36 focused UI tests and test build also pass. However, the current-head hosted test fails before those gates because the new story uses a noncanonical ASF header; see the inline finding. This PR is not ready until that file is corrected and the current-head CI passes. Diff-check and a merge-tree against main 0323714 are clean. I did not run packaged Electron or macOS/Windows validation. No schema/migration change is present. This is not a merge approval.
Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 |
There was a problem hiding this comment.
[P1] Use the repository's canonical ASF header spacing here. This line has three spaces after *, while the checked template requires five; npm run check:asf-headers exits 1 and the current-head hosted test stops before its remaining jobs. Align this header with the adjacent Storybook files and rerun CI.
Shift+Enter at the end of a draft that has reached the composer's row cap
inserts the line break but does not scroll: the new line, and the caret on
it, sit below the viewport until the next keystroke. The same happens when a
break in the bottom row pushes the rest of the line down, and after a
multi-line paste.
Measured in Chromium against the editor's own styles: execCommand
('insertLineBreak') at the draft end inserts the newline plus a placeholder
newline and parks the caret between them; the box grows by one line and the
caret paints on it. What the scripted commands skip, unlike a native
keypress, is revealing the caret.
After the Shift/Alt+Enter break, the multi-line insert seam and the
plain-text paste, scroll the editable to the caret: to the end when nothing
but the placeholder follows it, otherwise to the caret's line box — located
from the character before the caret when the caret itself paints no rect
(before a newline). No DOM, text or style change, so serialization and
drafts are untouched.
|
Header fixed in |
47fff77 to
a741bca
Compare
hqhq1025
left a comment
There was a problem hiding this comment.
Reviewed commit a741bcae8f1e12d471d333715fb7f30626519e7a. No new P0–P3 issue found in this head.
Compared with the prior reviewed commit 47fff771, the only change corrects indentation in the ASF license header of apps/desktop/stories/composer-caret-reveal.stories.tsx. The prior CI-blocking header finding is fixed. The caret behavior and tests are otherwise unchanged from that review; the previously reported two P2 behavior issues remained fixed there. No schema or migration change.
The current-head hosted test check passed. Locally, ASF headers, check:app-shell-hooks, git diff --check, and merge-tree against main ae71ab31 passed. I did not rerun Electron/Chromium behavior tests on this header-only commit, and the packaged Desktop remains untested. This is not merge approval.
Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.
|
This pull request has had no new commits for 30 days and has been marked stale. It will be closed in 7 days unless a new commit is pushed. Comments do not reset this timer: only a new commit does. If the pull request is intentionally long-lived, a maintainer can apply the |
|
This pull request has been closed because it received no new commits during the 7-day grace period. This is not a judgement on the merit of the change; it only keeps the review queue aligned with work that is actively in flight. The branch and review history are preserved. Push a new commit and reopen the pull request whenever the work is ready to continue. |
Fixes #5811.
Problem
Shift+Enter at the end of a draft that has reached the composer's row cap inserts the line break, but the editor does not scroll: the new line, and the caret on it, sit below the viewport until the next keystroke. The same happens when a break in the bottom row pushes the rest of the line down, and after a multi-line paste past the cap.
The issue's other claim — that the editable stays one line short and the caret falls outside the box — did not reproduce. Measured in Chromium against the editor's own styles:
execCommand('insertLineBreak')at the draft end inserts the newline plus a placeholder newline and parks the caret between them; the box grows by one line and the caret paints on it. What the scripted commands skip, unlike a native Enter keypress, is revealing the caret.Fix
After the Shift/Alt+Enter break, the multi-line insert seam (
beforeinput) and the plain-text paste (insertHTML),revealCaretAfterEdit()scrolls the editable to the caret: to the end when nothing but the placeholder follows it, otherwise to the caret's line box. A caret before a newline paints no client rect, so that case is located from the last painted leaf before it, found in document order within the editable (token chips and other inline wrappers nest text, so that leaf can sit outside the caret's own parent). No DOM, text or style change, so serialization and drafts are untouched.A caret at the end of a restored draft that ends in a newline needs nothing: Chromium paints it at the end of the last line.
Test plan
Product/Composer Caret Reveal, two stories): a draft typed past the row cap, then Shift+Enter at the end fromscrollTop 0, in the middle of the bottom row, and at the end of an upper line while scrolled to the bottom (the caret then sits before a newline with content after it, above the viewport); a Cmd+V of multi-line text and abeforeinputmulti-line insert at the end. Each step checks, from the DOM text before the caret rather than from the composer's helper, that the caret's line box lies inside the scroll viewport. Both stories fail without the reveal.EmptyHomealso asserts the capped-draft Shift+Enter scrolls.composer-shortcuts.test.tsx: 6 tests over a harness that models Chromium's measured DOM and rect behaviour, clampsscrollToplike a real scroll container, and walks nested leaves. Removing the reveal fails four; calling it before theexecCommandfails two; a sibling-only previous-leaf lookup fails the nested-caret test.<br>run mid-draft: the painted caret ends inside the viewport in each, and a break far from the end does not jump to the bottom.