Skip to content

fix: preserve caret and selection when inserting comment newlines - #618

Open
llemmm wants to merge 1 commit into
oss-compass:mainfrom
llemmm:fix/comment-newline-selection
Open

llemmm wants to merge 1 commit into
oss-compass:mainfrom
llemmm:fix/comment-newline-selection

Conversation

@llemmm

@llemmm llemmm commented Oct 23, 2026

Copy link
Copy Markdown

Problem

Shift+Enter and Ctrl+Enter in the Lab, Sandbox, Hatch and Graduate comment inputs always append a newline to the end of the comment. They ignore the caret position and leave selected text intact.

Reproduction

  1. Type abcdef in a comment input.
  2. Move the caret between c and d, then press Shift+Enter or Ctrl+Enter.
  3. The original input becomes abcdef\n instead of abc\ndef.
  4. Selecting cd and using either shortcut should replace the selection with a newline, but the original code appends one instead.

Change

  • Insert a newline using the textarea's current value and selection range.
  • Flush the controlled value update before restoring the collapsed caret immediately after the inserted newline.
  • Add forty regression cases across all four inputs: both shortcuts at the start/middle/end and over selected text, plain Enter submission, and loading protection.

Only four comment components and one test file change. IME handling, attachment limits and attachment deletion behavior are intentionally unchanged; this is separate from the IME guards in #480.

Validation

  • Normal repository dependencies, including the real MUI TextareaAutosize; the new test source mocks only translations and image preview.
  • Same forty regression tests on original source: 24 fail / 16 pass; fixed source: 40 pass.
  • Baseline 4f2d8aced18cf5e71928f1e7931525ac6f7d8293: 31 suites / 136 tests pass.
  • Exact proposed source tree 5bc4a58a814baae4c5eabf197347be4cf43635ee: 32 suites / 176 tests pass.
  • Full yarn build passes, including default lint/type checking and production build steps.
  • Scoped ESLint: zero errors and zero new warnings. One pre-existing react-hooks/exhaustive-deps warning about the Lab component's boxRef.current cleanup remains unchanged. Original files were separately linted through stdin with their actual filenames and the same configuration. No rules or warnings were suppressed, and unrelated cleanup code was not changed.
  • Linux / Node 22.22.0 / Yarn 1.22.22, pinned i18n submodule, unchanged lockfile. CPU-only bounded validation. Upstream CI uses Node 18.x; these results do not claim that GitHub CI has run or passed. No real-browser end-to-end test was run.

DCO

The commit contains the contributor's explicitly authorized Signed-off-by trailer, using their GitHub privacy email.

Signed-off-by: llemmm <165860939+llemmm@users.noreply.github.com>
@vercel

vercel Bot commented Oct 23, 2026

Copy link
Copy Markdown

@llemmm is attempting to deploy a commit to the codersett's projects Team on Vercel.

A member of the Team first needs to authorize it.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant