Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vi-mode] Undo now leaves the cursor under the position at the start of the deletion #2045

Merged
merged 9 commits into from
Sep 22, 2021

Conversation

springcomp
Copy link
Contributor

@springcomp springcomp commented Dec 16, 2020

PR Summary

Fixes #1673
Fixes #2408

This PR changes undo so that a deleted text is inserted in the buffer and resetting the cursor at the position where it was when deletion of text occurred. I believe this is also making it more consistent with how most text editors behave.

To implement this PR I also slightly changed the AcceptSuggestion and AcceptNextSuggestionWord methods which were doing a replacement of the buffer. This PR now makes those methods add the appropriate portion of text so that undoing the operation behaves more inline with most users’ expectations. Externally, the behaviour of those methods has not changed.

This PR also changes SwapCharacters to make it an atomic operation while still moving the cursor after swapping characters. This preserves the original behaviour. However, it slightly alters the way the cursor is now positioned when undo occurs, but I’m not sure whether this can be seen as a breaking change or not.

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure you've added one or more new tests
  • Make sure you've tested these changes in terminals that PowerShell is commonly used in (i.e. conhost.exe, Windows Terminal, Visual Studio Code Integrated Terminal, etc.)
  • User-facing changes
    • Not Applicable
Microsoft Reviewers: Open in CodeFlow

PSReadLine/Prediction.cs Show resolved Hide resolved
PSReadLine/UndoRedo.cs Outdated Show resolved Hide resolved
@ghost ghost added the Needs-Author Feedback label Jan 7, 2021
@ghost ghost removed the Needs-Author Feedback label Jan 20, 2021
Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

@springcomp Sorry for the looooong delay. I rebased your code and made some refactoring and updates. Will merge this PR shortly.

@daxian-dbw daxian-dbw merged commit 1966609 into PowerShell:master Sep 22, 2021
@springcomp springcomp deleted the #1673 branch September 22, 2021 15:01
@springcomp
Copy link
Contributor Author

@daxian-dbw thanks a lot 🙏. I never lost hope 😉.

@ghost
Copy link

ghost commented Oct 28, 2021

🎉 v2.2.0-beta4 has been released which incorporates this pull request. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants