Repository navigation
Delete Duplicate Lines: ignore the line a selection ends on at column 1 - #350851
Draft
Federico Brancasi (federicobrancasi) wants to merge 2 commits into
Draft
Federico Brancasi (federicobrancasi) wants to merge 2 commits into
Federico Brancasi (federicobrancasi) wants to merge 2 commits into
Conversation
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>
Contributor
There was a problem hiding this comment.
🟡 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>
Federico Brancasi (federicobrancasi)
requested a balanced review from Copilot
November 28, 2026 15:02
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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
selecting the first three lines and running Delete Duplicate Lines removed the second
alphaand also the secondbeta, 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.
./scripts/test.sh --run src/vs/editor/contrib/linesOperations/test/browser/linesOperations.test.ts./scripts/test.sh --runGlob "**/editor/**/*.test.js"node_modules/.bin/oxlinton the changed files