Skip to content

Fix Cmd+A highlight missing last line on trailing-newline documents#123

Open
BatchZero wants to merge 1 commit intoCodeEditApp:mainfrom
BatchZero:fix/issue-121-trailing-line-highlight
Open

Fix Cmd+A highlight missing last line on trailing-newline documents#123
BatchZero wants to merge 1 commit intoCodeEditApp:mainfrom
BatchZero:fix/issue-121-trailing-line-highlight

Conversation

@BatchZero
Copy link
Copy Markdown

Summary

  • TextLineStorageRangeIterator.next() stopped at currentPosition.range.max < range.max. When the document ends with a line ending, line storage holds a trailing empty line at the very offset where the previous line's range.max equals range.max, so the iterator never reached it.
  • That meant selectAll selected the line (Cmd+C/Cmd+V worked) but TextSelectionManager.getFillRects never drew its selection rect — exactly the symptom reported in 🐞 Command-A (Copy All) is capturing, but not highlighting #121.
  • The fix lets the iterator yield a length-0 line whose location equals range.max. Every other case is left unchanged, including:
    • linesInRange(NSRange(location: 6, length: 0)) (used by editingEndOfDocumentInvalidatesLastLine)
    • partial ranges that end exactly at the start of a non-empty line (linesInRange should not include that line)
    • empty lines in the middle of a document (already covered by rangeIteratorDoesNotSkipEmptyLines)

Fixes #121.

Test plan

  • swift test — all suites green (44 XCTest cases + 66 swift-testing cases)
  • New regression test rangeIteratorIncludesTrailingEmptyLine in TextLayoutManagerTests covers the trailing-newline scenario

`TextLineStorageRangeIterator.next()` stopped iterating once the current
line's `range.max` reached `range.max`, but the trailing empty line
created for documents ending with a line ending sits at the very same
offset (length 0). The iterator never reached it, so `selectAll`
selected it (Cmd+C/Cmd+V worked) but `getFillRects` never drew its
selection rect.

Allow the iterator to yield a length-0 line whose location equals
`range.max`, leaving every other case unchanged.

Fixes CodeEditApp#121.
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.

🐞 Command-A (Copy All) is capturing, but not highlighting

1 participant