Skip to content

fix(editor): Cmd+X cuts current line and Cmd+A highlights every line on trailing newline (#1075)#1080

Merged
datlechin merged 1 commit into
mainfrom
fix/editor-cut-line-and-select-all-trailing
May 7, 2026
Merged

fix(editor): Cmd+X cuts current line and Cmd+A highlights every line on trailing newline (#1075)#1080
datlechin merged 1 commit into
mainfrom
fix/editor-cut-line-and-select-all-trailing

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

Two related editor fixes from issue #1075.

Cmd+X cuts the current line when no selection

Matches VS Code, Sublime, JetBrains, and Xcode source editor. New LineCutCalculator (pure, testable) drives the decision in EditorEventRouter:

  • With selection → cut the selection (existing behavior preserved).
  • No selection → cut the current line including its trailing newline, using NSString.lineRange(for:) (Apple's documented line-boundary API, handles LF / CR / CRLF correctly).
  • No-op cases: empty buffer, cursor past end, cursor at the trailing-empty position with no preceding line.

Cmd+A highlights every line, not just the first, on trailing-newline buffers

In TextSelectionManager+FillRects.swift, the else branch was wrongly entered for the LAST text line whenever intersectionRange.max == lineStorage.length, and rectForOffset(lineStorage.length) resolved to the trailing-empty-line position at the leading edge — collapsing the highlight to width 0.

Fix: detect when the line ends with a line-break character via LineEnding(line:) and treat that case the same as a non-end-of-doc line — extend the highlight to the right edge.

Reproduced in unit test before the fix:

Buffer: "select * from users;\nselect * from users;\n"  (length 42)
Before fix → fill rects:
  [0] x=0 w=1000  ← line 1 highlighted ✓
  [1] x=0 w=0     ← line 2 INVISIBLE ✗
After fix → both lines have w=1000.

Test plan

  • TableProTestsLineCutCalculatorTests (13 tests) all pass.
  • CodeEditTextViewTestsSelectAllWithTrailingNewlineTests (13 tests) all pass.
  • CodeEditTextViewTestsCmdShiftLeftAtEndOfDocumentTests (9 regression tests) all pass.
  • Manual SQL editor:
    • Type a single line, place cursor anywhere, Cmd+X → entire line cut to clipboard.
    • Multi-line, cursor on middle line, Cmd+X → that line + trailing \n cut, lines below shift up.
    • Make a selection, Cmd+X → only the selection is cut (no regression).
    • Cmd+C with selection still works.
    • Type a query ending with \n (extra empty line at the bottom). Cmd+A → every line shows blue highlight, including the one before the trailing empty line.
    • Type a query NOT ending with \n. Cmd+A → every line highlighted, last line's highlight stops at the text end (no extension to right edge).

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@datlechin datlechin merged commit 2987648 into main May 7, 2026
1 check passed
@datlechin datlechin deleted the fix/editor-cut-line-and-select-all-trailing branch May 7, 2026 12:31
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