Skip to content

fix(ui): reveal the tail line after a line break at the draft's end - #6245

Open
ggbdpq wants to merge 3 commits into
apache:mainfrom
ggbdpq:fix/5811-composer-line-growth
Open

ggbdpq wants to merge 3 commits into
apache:mainfrom
ggbdpq:fix/5811-composer-line-growth

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Shift+Enter with the caret at the very end of the draft inserts the break but the composer neither grows nor scrolls: under the editor's white-space: pre-wrap, Chromium's insertLineBreak parks the caret on a line that gets no line box, so at the 10-row cap nothing can scroll toward a line with no box — the caret sits out of sight until the next typed character. A restored draft ending in \n parks its caret on the same boxless line.

Fix both shapes at the shared root, in the shell (no dependency patch):

  • white-space: break-spaces on the composer editable gives every preserved break a real line box, so the box grows immediately and the tail becomes scrollable. !important is required: Astryx ships its pre-wrap through a stylex utility at (3,1,0) specificity that no plain Maka selector beats.
  • revealTailLineBreak in the Composer scrolls the editor to the tail after insertLineBreak when the caret ends the draft — deterministic at the cap, a no-op while the content fits. Wired into the Shift/Alt+Enter path and the multi-line insert replay, so a paste ending in a newline reveals its tail. Mid-draft breaks never scroll; the browser already reveals those.

One residual left as-is on purpose: restoring a long draft that ends in \n now gets a real tail line (geometry fixed), but the editor still opens at the top rather than auto-scrolling to the end-of-draft caret — scrolling a restore to its tail felt like the wrong default. Happy to add it if maintainers prefer restore-to-caret.

Fixes #5811

Verification

Check Result
New unit tests (composer-tail-line-break.test.tsx) red before (4 × AssertionError: 0 !== 220 on the four tail scenarios), green after (5/5) — re-verified independently against the built dist both ways
@maka/ui full suite 781/781 pass (includes the 30 existing Enter/Shift+Enter shortcut contracts)
desktop shell-layout-widths.test.mjs (reads composer.css) 6/6 pass
biome check --linter-enabled=true on touched files clean (the UI surface is formatter-excluded per the #415 source contract, so the lint gate is the applicable one)
npm run check:asf-headers pass
Playwright e2e (real-layout scrollTop/scrollHeight assertion) NOT run locally — needs the full desktop build plus an Electron window; requesting CI coverage here

AI use

Implemented by GLM-5.3-Flash (ZCode). Root cause verified against the installed @astryxdesign/core 0.6.3 dist (no auto-resize/scroll logic in the library; the editable is capped by an inline maxHeight), and the red/green runs above were re-executed independently before opening this PR.

Checklist

  • Tests pin the wrapper contract; layout geometry is covered by the CSS override (no unit-test layout environment available)
  • No dependency patches added or extended
  • ASF headers present on new files

Shift+Enter at the very end of the draft moves the caret onto a line
Chromium gives no line box under `white-space: pre-wrap`: the editor
stays one line short of the caret and, at the 10-row cap, nothing can
scroll toward a line with no box — the caret sits out of sight until
the next typed character turns it into content. The same boxless line
is what a restored draft ending in "\n" parks its caret on.

Fix the shared root in the shell, not the editor library:

- `white-space: break-spaces` on the editable (renderer styles) gives
  every preserved break a real line box, so the box grows immediately
  and the tail becomes scrollable. `!important` because Astryx ships
  pre-wrap through a stylex utility at (3,1,0) specificity that no
  plain Maka selector beats.
- `revealTailLineBreak` (composer.tsx) scrolls the editor to the tail
  after `insertLineBreak` when the caret ends the draft — deterministic
  at the cap, a no-op while the content fits. Wired into the
  Shift/Alt+Enter path and the multi-line insert replay, so a paste
  ending in a newline reveals its tail too.

Fixes apache#5811

Generated-by: GLM-5.3-Flash (ZCode)
@github-actions github-actions Bot added the effort/M Under 500 readable lines label Oct 22, 2026

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Reviewed 38cfbcf against main 59f61cf, including all three changed files. The CSS changes whitespace handling, and Composer now conditionally scrolls after inserting a line break. Two P2 issues remain, detailed inline: the real tail-caret shape bypasses the reveal at the row cap, and the editable-only whitespace override breaks the existing next-prompt Storybook contract/CI.

Using the production WorkHub/Composer Storybook and real Chromium, I typed a 14-line draft, moved to its end and pressed Shift+Enter. The scroll height grew from 316 to 338 px with a 220 px viewport, but scrollTop stayed 96 rather than reaching 118. The new predicate saw a connected newline text node at offset zero and returned without scrolling. A deferred-scroll control reaches 118. A separate restored-text input reproduces the same failure.

The production next-prompt story fails in all four 1280/720 px × light/dark cases. Restoring only the previous whitespace value makes all four plays pass, matching the exact-head CI failure. This failure is attributable to this PR.

Fresh dependencies/patches, the normal clean test build, renderer and Storybook builds, all 781 UI tests, six shell-layout tests, lint/ASF/whitespace checks passed. The five new unit tests pass, while replacing only Composer with actual main makes four fail; their mocked caret does not cover the newline text-node shape observed in Chromium. The static merge with current main is clean. AI declaration and Generated-by are present. No protocol or database change is involved. I did not run native Electron or platform IME sessions.

Comment thread packages/ui/src/composer.tsx Resolved
A real Shift+Enter at the very end of the draft does not leave a `<br>`
after the caret: under `white-space: break-spaces` Chromium parks the
inserted break as a literal `\n` text node and the collapsed selection
at its offset 0. `caretAtContentEnd` read any remainder inside the
caret's own text node as content still to come and returned false, so
`revealTailLineBreak` skipped the scroll — measured in real Chromium
(Storybook's WorkHub composer), a 14-line draft at the 220px cap grew
scrollHeight 316 to 338 while `scrollTop` stayed parked at its pre-break
offset (89-96 across runs) instead of the required 118, leaving the new
tail line outside the scrollport.

Treat a `\n`-only remainder like the trailing `<br>` it replaces: the
caret ahead of it still ends the draft. A newline followed by any other
character keeps the caret mid-draft and never scrolls.

Verified in headless Chromium against the built Storybook
(product-workhub--standard-composer): with this change the same
keystrokes land `scrollTop` 118 = scrollHeight 338 - clientHeight 220,
and the recorded selection shape is TEXT_NODE `"\n"` at offset 0 both
before and after. Unit tests cover the shape and its mid-draft negative.

Generated-by: GLM-5.3-Flash (ZCode)
…itable

apache#5811 gave the composer editable `white-space: break-spaces` so a
trailing line break gets a line box, but the next-prompt suggestion —
which overlays the same grid cell precisely so a wrapping suggestion
reserves the same height as the accepted draft — still measured text
with `pre-wrap`. The two wrapped trailing whitespace differently, and
the NextPromptSuggestion story's play, which asserts the editor's
metrics equal the offered suggestion's (client rects, font,
letterSpacing, whiteSpace, wordBreak), failed in all four renders
(light/dark x 1280/720).

Sync the mirror to break-spaces: the editable's value is the contract,
and the suggestion reserves height by matching it.

Verified with the production render smoke's own harness on the built
Storybook: `product-workhub--next-prompt-suggestion` passes all four
jobs with this change and fails with `pre-wrap` restored
(`metrics(input)` no longer deep-equals the offered metrics).

Generated-by: GLM-5.3-Flash (ZCode)

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Reviewed 5bb8257d4f781760fcfb8dfd12907e3f17a866b3, including both follow-up commits (three-file increment, +35/-4) after 38cfbcfb. Both previous P2 findings are fixed: a trailing newline text node now counts as the caret's tail, and the next-prompt overlay uses the editable's break-spaces whitespace contract. I found no new confirmed P0–P2 issue.

Using the actual WorkHub/Composer Storybook in Chromium, all four next-prompt plays passed (1280/720 px × light/dark, with the actual viewport width asserted). Eight capped-draft checks passed across keyboard-built and multiline-filled drafts: after Shift+Enter, the 220 px editor's scroll height grows from 316 to 338 px and scrollTop moves from 96 to 118, exposing the new tail line. A short draft grows from 30 to 52 px, and a mid-draft break does not jump to the tail. I inspected the 720 px dark capture.

The controls isolate both fixes. Loading only the previous Composer makes the new trailing-newline regression fail (6 pass, 1 fail). Restoring only the overlay's old pre-wrap rule makes all four real next-prompt plays fail their original metrics comparison; the editor remains break-spaces while the offered overlay is pre-wrap. These controls change only loaded test modules or browser-served CSS, not source files.

The normal clean root test build, production renderer and Storybook builds, all 803 shared-UI tests, six shell-layout tests, changed-file lint, ASF headers and git diff --check passed. Compiled UI test files match all 96 source test files with no extra stale tests. Dependencies and patches were reused from a fresh installation with identical inputs. The static merge with current main 15d0a0dd19d39e2bc09ae35940e432c636982315 is clean and its epoch guard passes at 228; this PR makes no protocol change. Exact-head CI run 39950332742 succeeded.

I did not run native Electron, platform IME sessions or a persisted-draft restoration flow. The multiline-filled browser cases exercise editor content, not a real stored-draft reload. The documented choice to open long restored drafts at the top remains; this fix does not add automatic restore-to-caret scrolling.

@github-actions github-actions Bot added the stale No qualifying activity within the lifecycle policy window label Nov 23, 2026
@github-actions

Copy link
Copy Markdown

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 pinned label.

@ggbdpq

ggbdpq commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebase & full-chain verification refresh (2026-11-25)

Context: upstream main switched to the native/rust-preview line after 9175a2b8 (2026-11-22), removing the TypeScript app stack this fix targets. Per contributor decision, this PR is re-verified against the last TypeScript main tip 9175a2b8fc04edeac87423d90ff637bbdf4ad45d (2026-11-22) so it stays reviewable/mergeable when the TypeScript line returns.

Rebased onto 9175a2b8, 5bb8257d4f781760fcfb8dfd12907e3f17a866b3 → cfe38228ee6e51fd6ed5f4d604c86e3273729bbc. Not pushed (branch left untouched).

Check Result
Branch fix/5811-composer-line-growth
Rebase clean (3 commits replayed)
git am 3 patch(es) apply cleanly onto 9175a2b (throwaway worktree)
Build full workspace build green (npm run build); @maka/ui + @maka/desktop dist rebuilt
Tests composer-tail-line-break.test.js: 7/7 pass (node --test packages/ui/dist/__tests__/composer-tail-line-break.test.js); @maka/ui full suite per-file: 97/98 files fully green, executor-model-picker.test.js 14/20 — the 6 failures reproduce identically on pristine 9175a2b8 without the fix (baseline-prefixed, runtime/environment-dependent, unrelated surface); shell-layout-widths.test.js (desktop): 6/6 pass
Ablation baseline composer.tsx with the new tests kept → 5/7 red (AssertionError: 0 !== 220 on the tail-reveal scenarios) → fix re-applied → 7/7 green
Sibling sweep rg insertLineBreak packages/ apps/ → 2 production call sites (composer.tsx:1074 multi-line insert replay, composer.tsx:1654 Shift/Alt+Enter), both wired to revealTailLineBreak; white-space: pre-wrap remaining sites are non-composer surfaces (chat-message, settings, workhub, etc.), out of this fix's family; the composer editable override + .maka-composer-next-prompt mirror pair are both updated
Lint / headers biome check --linter-enabled=true on the 3 touched files: clean; npm run check:asf-headers: pass
Real-path repro Not verified locally — the visual scrollTop reveal needs a real Chromium layout inside the Electron desktop window; covered by the deterministic unit tests (jsdom harness asserting scrollTop) and requesting CI e2e coverage as the PR already notes

Attribution: original fix by @ggbdpq; rebase & verification refresh by GLM-5.3-Flash (ZCode).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines stale No qualifying activity within the lifecycle policy window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Composer does not grow (or scroll) for Shift+Enter at the end of the draft

2 participants