Skip to content

Delete Duplicate Lines: ignore the line a selection ends on at column 1 - #350851

Draft
Federico Brancasi (federicobrancasi) wants to merge 2 commits into
mainfrom
fbrancasi/delete-duplicate-lines-end-column
Draft

Federico Brancasi (federicobrancasi) wants to merge 2 commits into
mainfrom
fbrancasi/delete-duplicate-lines-end-column

Conversation

@federicobrancasi

@federicobrancasi Federico Brancasi (federicobrancasi) commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Selecting whole lines, with Shift+Down or by dragging over the line numbers, leaves the selection at column 1 of the line after the last selected one. Delete Duplicate Lines still included that line. So it could delete a line the user didn't select, when that line repeats one in the selection, and the selection afterwards covered it as well.

For example, in

alpha
beta
alpha
beta
omicron

selecting the first three lines and running Delete Duplicate Lines removed the second alpha and also the second beta, which wasn't selected.

This PR leaves that line out, the same way Copy, Move, Sort, Reverse and Delete Lines already do.

This also helps when nothing is selected and the command runs on the whole file: if the file ends with a newline and has another blank line, the empty last line was deleted as a duplicate, which removed the final newline. It's now kept.

How to test

One new test selects the first three lines of the example; another runs the command on a whole file that ends with a newline. Both fail without the fix.

Command Result
./scripts/test.sh --run src/vs/editor/contrib/linesOperations/test/browser/linesOperations.test.ts passed
./scripts/test.sh --runGlob "**/editor/**/*.test.js" 7907 passing
node_modules/.bin/oxlint on the changed files passed

Selecting whole lines leaves the selection at column 1 of the next line.
Delete Duplicate Lines still included that line, so it could delete a
line that wasn't selected. Exclude it, like Copy, Move, Sort, Reverse and
Delete Lines do.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 28, 2026 14:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests lack regression coverage for preserving the trailing newline and empty cursor selection when the action runs implicitly on the whole document.

1 open issue
What changed in this PR

Updates the editor’s Delete Duplicate Lines command to respect whole-line selection boundaries, matching other line operations.

Changes:

  • Excludes the line where a multiline selection ends at column 1, with consistent replacement ranges and selection updates.
  • Preserves the final newline during whole-document duplicate removal.
  • Adds a regression test checking that the unselected line remains and the resulting selection is correct.
File Description
src/​vs/​editor/​contrib/​linesOperations/​test/​browser/​linesOperations.test.ts Tests the column-1 selection boundary and resulting selection.
src/​vs/​editor/​contrib/​linesOperations/​browser/​linesOperations.ts Adjusts the effective ending line for duplicate removal and selection calculations.

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified, although tests were not rerun.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

2 participants