Skip to content

fix(editor): cmd+arrow, up arrow, and gutter highlight at end of query - #1014

Merged
datlechin merged 1 commit into
mainfrom
fix/editor-end-of-line-selection
May 6, 2026
Merged

datlechin merged 1 commit into
mainfrom
fix/editor-end-of-line-selection

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

Three end-of-line/end-of-document bugs in the SQL editor, all rooted in NSRange.contains being half-open and silently dropping the offset == documentLength case.

  • Cmd+Left/Right (and Shift variants) at the end of the query did nothing. extendSelectionVisualLine looked up the visual fragment with getLine(atOffset:) (returns nil for an offset equal to the line length) and unconditionally subtracted the document's detected line-ending length even when the line itself had no trailing newline, capping the right bound one short. The fragment lookup now falls back to fragments.last and the line-ending length is computed from the actual line text via LineEnding(line:), matching the pattern extendSelectionLine already uses. Fixes Can't using cmd + arrow keys when on the last letter #1007.
  • Up arrow on the first line at end-of-document didn't jump to the start. extendSelectionVertical's first/last line check used lineStorage.first?.range.contains(offset). For a single-line query with the caret at offset length that returns false, so it fell through to a geometry probe that found no line above and bailed. Now compares line IDs via textLineForOffset(offset), which already returns the last line for offset == length. Symmetric Down-on-last-line path is fixed too.
  • Caret at end-of-document lost the line-number color in the gutter even though the line background stayed shaded. drawLineNumbers matched lines via IndexSet.intersects(integersIn: lineRange) (half-open). Empty selections now route through textLineForOffset, mirroring how drawSelectedLines already handles end-of-document carets.

Test plan

  • swift test in LocalPackages/CodeEditTextView (76/76 passing) including the new VisualLineEndOfDocumentTests (6 cases, 5 of which failed before the fix) and CmdUpAtEndOfDocumentTests (5 cases, 1 failed before the fix)
  • xcodebuild ... -only-testing:TableProTests/GutterHighlightTests (3 cases × arm64/x86_64) passes
  • Full app build (xcodebuild ... -scheme TablePro build) succeeds
  • swiftlint --strict clean on every modified and added file
  • Manual: place caret at the end of a query, press Cmd+Left, Cmd+Right, Cmd+Shift+Left, Up arrow on a single-line query, and confirm the line number stays highlighted while the caret sits at the end

@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 3712bae into main May 6, 2026
1 check passed
@datlechin
datlechin deleted the fix/editor-end-of-line-selection branch May 6, 2026 02:55
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.

Can't using cmd + arrow keys when on the last letter

1 participant