Visitar URL original
Feature: New command - Delete Duplicate Lines by codeclown · Pull Request #119480 · microsoft/vscode · GitHub
Skip to content

Feature: New command - Delete Duplicate Lines - #119480

Merged
Alexandru Dima (alexdima) merged 2 commits into
microsoft:mainfrom
codeclown:delete-duplicates
Oct 27, 2021
Merged

Alexandru Dima (alexdima) merged 2 commits into
microsoft:mainfrom
codeclown:delete-duplicates

Conversation

@codeclown

Copy link
Copy Markdown
Contributor

Description

VS Code implements a set of useful commands to mutate lines in the current selection(s), e.g.

  • Sort Lines Ascending
  • Sort Lines Descending

This PR implements a new command:

  • Delete Duplicate Lines

Screenshot:

image

This is useful when mass-editing lines of text. For me personally it's probably the last thing that I miss from Sublime Text, as a converted VS Code user.

Open questions

  • Is this feature mergeable to VS Code, or should it be separated as an extension instead? I think it'd make sense to have in the core, to accompany the other line mutating commands.
  • Does the selection handling in this PR look okay? This is my first PR to this codebase and I'm not 100% confident about that part.

If anything needs adjusting, I'm happy to alter the PR. Please do let me know.

@ghost

Deleted user (ghost) commented Mar 22, 2021 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@SnirBroshi

Snir Broshi (SnirBroshi) commented Mar 23, 2021 •

Copy link
Copy Markdown
Contributor

I think the logic should instead be: if there is one selection, delete duplicate lines like you did, but if there are multiple selections, delete duplicate selections.
IMO this handles more use cases than what you've done with multiple selections (e.g. if I select all the words I can remove duplicate words), which is equivalent to running the command on each selection separately.

Also, this would probably be closed as an "extension-candidate", which makes sense but doesn't justify having sorting commands built-in while this isn't.
Here's an extension written by someone actually in the VSCode team that does what you want - https://marketplace.visualstudio.com/items?itemName=Tyriar.sort-lines
Personally I think VSCode has no underlying logic to deciding what's built-in and what isn't, I'd vote to either having this command added or the sorting commands removed as an extension-candidate.

Btw PRs need to have an issue associated with them, I'm assuming a really old issue already exists but I couldn't find any

@codeclown

Copy link
Copy Markdown
Contributor Author

I think the logic should instead be: if there is one selection, delete duplicate lines like you did, but if there are multiple selections, delete duplicate selections. IMO this handles more use cases than what you've done with multiple selections (e.g. if I select all the words I can remove duplicate words), which is equivalent to running the command on each selection separately.

I based the behaviour on Sublime Text. It's also consistent with the other built-in commands, which are dealing with lines, not selections. I also think it'd just be confusing to the user if the command switched between deleting lines and deleting selections based on the amount of selections.

From personal experience, I don't recall ever needing a "delete duplicate selections" action. If there's need for it then that could just be implemented as a separate command.

Also, this would probably be closed as an "extension-candidate", which makes sense but doesn't justify having sorting commands built-in while this isn't. [...]

Yep, I agree with this, also listed this as a question above. Will leave it to project stakeholders to decide.

@alexdima Alexandru Dima (alexdima) added this to the April 2021 milestone Mar 23, 2021
@SnirBroshi

Copy link
Copy Markdown
Contributor

It's also consistent with the other built-in commands, which are dealing with lines, not selections. I also think it'd just be confusing to the user if the command switched between deleting lines and deleting selections based on the amount of selections.

Duplicate selection & Copy/Cut commands work differently based on the selection. I'd argue that a separate command is more confusing and annoying, but I guess both use cases might be useful, so idk.

@alexdima Alexandru Dima (alexdima) added the editor-commands Editor text manipulation commands label Oct 27, 2021
@alexdima

Copy link
Copy Markdown
Member

Thank you!

@alexdima
Alexandru Dima (alexdima) merged commit 9264622 into microsoft:main Oct 27, 2021
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

editor-commands Editor text manipulation commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants