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

Phrase-level undo command #317

Open
11 tasks
pokey opened this issue Nov 8, 2021 · 2 comments
Open
11 tasks

Phrase-level undo command #317

pokey opened this issue Nov 8, 2021 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@pokey
Copy link
Member

pokey commented Nov 8, 2021

The problem

As we become more adventurous with long command phrases, it becomes more painful to undo a command phrase that has gone wrong. We'd like to be able to undo everything done by a single phrase, even if it corresponds to many edits, potentially across multiple editors

The solution

We should probably implement this one as a separate extension. Seems more generic than just for cursorless

M1: The basics

  • Take snapshot of document upon opening it, and after any change in an open editor
  • Any time talon sends pre-phrase signal, set a flag, and then any time a document changes mark the previous version so that we can snap back to it
  • When user issues a "phrase-level undo", extension will repeatedly issue undo commands in each editor that has had a change until its contents match snapshot. Need some mechanism to keep this from getting out of hand if something is amiss and for whatever reason the document never matches the snapshot
  • Keep a sequence of these "phrase-level actions" so can undo multiple in a row

M2: Other types of actions

  • Keep track of editor selections and undo those
  • Keep track of editor visible ranges and undo scroll
  • Allow extensions to register reverse actions. That way can undo other side effects, make it easier to handle scroll, and not add spam to cursorless selection history tracking

M3 Unopened documents

Handle changes to documents that are not open in an editor

  • Extensions can signal that they are about to change a document that is not open
  • Any time a document changes that is not open, if it has been signalled by an extension, we handle it like an open editor, except that we can't use undo action; we have to just restore the snapshot
  • If a document changes that is not open and hasn't been signalled by an extension, we refuse to handle it as an undo because it could be a git command or something and we don't want to mess something up. Or I guess we could warn

M4 Undo tree

  • Add an undo tree so that if user issues an undo, then does something, that creates a branch. Can steal a display from a git log plugin or something
@pokey pokey added the enhancement New feature or request label Nov 8, 2021
@pokey pokey changed the title Undo tree with phrase-level granularity Phrase-level undo command Nov 10, 2021
@pokey pokey added this to To Do in Increasing fluency Nov 10, 2021
@pokey pokey added this to the On deck milestone Jan 18, 2022
@tankorsmash
Copy link

Coming from vim, I'm looking forward to the undo tree! I think the only pain point with Cursorless so far is the undo'ing an accidental command! It's surprisingly easy to have many words accidentally get inserted, and I'm used to being able to just press u to undo everything.

Thank you for Cursorless!

@pokey
Copy link
Member Author

pokey commented Feb 2, 2024

Coming from vim, I'm looking forward to the undo tree! I think the only pain point with Cursorless so far is the undo'ing an accidental command! It's surprisingly easy to have many words accidentally get inserted, and I'm used to being able to just press u to undo everything.

Yeah undo tree is def the biggest thing I miss from my vim days. You get drunk on the confidence it gives you

Thank you for Cursorless!

You're welcome! Glad you're finding it helpful ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

2 participants