Skip to content

fix(core): Preserve empty lines when copying selected text - #1103

Merged
kommander merged 2 commits into
anomalyco:mainfrom
benkoppe:fix-selection-empty-lines
May 26, 2026
Merged

kommander merged 2 commits into
anomalyco:mainfrom
benkoppe:fix-selection-empty-lines

Conversation

@benkoppe

@benkoppe benkoppe commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

OpenTUI currently completely drops empty logical lines from selected text. This means highlight-copying code can remove intentional blank lines, which often breaks formatting.

This affects Opencode heavily, making copying/pasting code excessively annoying because all blank lines are completely erased.

The behavior was caused by extractTextBetweenOffsets. Newline output was gated on whether the line had content, therefore empty selected lines never emitted their newline. This PR changes newline emission to be based on whether the newline offset is inside the selected range, regardless of line content.

Includes a regression test for:

const a = 1

const b = 2

copying back exactly as selected.

@benkoppe benkoppe changed the title Preserve empty lines when copying selected text fix(core): Preserve empty lines when copying selected text May 22, 2026
@benkoppe

Copy link
Copy Markdown
Contributor Author

This issue seems to be cited in Opencode multiple times:

anomalyco/opencode#10098
anomalyco/opencode#16521
anomalyco/opencode#25623

@kommander
kommander merged commit 7f3a71e into anomalyco:main May 26, 2026
21 checks passed
@benkoppe

benkoppe commented May 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks so much @kommander , can't tell you how much this will improve my workflow!

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.

2 participants