Skip to content

Allow custom editors to hook into Edit menu actions such as copy, undo, redo, ... #90110

Closed

Description

@mjbvz

Problem
For custom editors, we currently support undo/redo using keyboard shortcuts. However you cannot undo and redo using the Edit menu in VS Code.

Other commands like copy and paste only work in webviews because we do a execCommand('copy') call. This ends up copying the correct text but bypasses the custom copy command we have for webviews:

export class CopyWebviewEditorCommand extends Command {

Proposal
I believe that we need a way to either:

  • Have the global undo / redo commands from the menu bar call into our webview specific code if a webview is focus

  • Or allow webview to register replacement undo / redo commands in the edit menu when they are focused

/cc Benjamin Pasero (@bpasero), Alexandru Dima (@alexdima), SteVen Batten (@sbatten)

Activity

  1. added
    custom-editors
    on Feb 5, 2020
  2. mjbvz commented on Feb 6, 2020

    @mjbvz
    ContributorAuthor

    Also adding Kai Maetzel (@kieferrm) and Peng Lyu (@rebornix) for notebooks

  3. bpasero commented on Feb 6, 2020

    @bpasero
    Contributor

    I would think that Undo/Redo should use some global (workbench level?) thing that keeps track of all the undos/redos that are possible and then run them. This would be the beginning of workspace-level undo/redo. We can start simple and only let the text and custom editors add edits (e.g. not the file explorer which we could do later).

    I briefly talked about this with Alex when we discussed custom editors a while ago, maybe he can chime in with his point of view for how such a system would work. There are some tricky bits around this as soon as we add non-editor related undo/redo because once you move focus from one editor to another, you need to basically move all edits in the history for that editor to the front. Alternatively we could track edits per editor and simply navigate in the edit stack of the editor that has focus.

  4. alexdima commented on Feb 6, 2020

    @alexdima
    Member

    Currently, undo and redo are completely owned by the editor, with a small workaround where they check if the current focused element is a <textarea> or <input> and then they invoke document.executeCommand('undo') and document.executeCommand('redo').

    To get a more collaborative story, I believe the best way would be to have a workbench service where various places can contribute undo/redo stack elements. This needs to be thought through such as to not disrupt the current undo/redo behaviour and IMHO this needs to be adopted somehow by the editor.

    Here is the current undo/redo implementation for the editor (this is stored per text buffer): vs/editor/common/model/editStack.ts. By looking at the way that class is used already some requirements for such a workbench service can be devised:

    1. the ability to remove everything. Currently, when someone calls model.setValue(), the undo/redo stack for that text buffer is removed entirely. The same happens when disposing a text buffer, the undo/redo stack is cleared. The reason is that a subsequent load of the file from disk could end up loading different content and the undo/redo stack could be invalid.
    2. the ability to push a stack element and have it be "opened" such that subsequent edits can go in the same stack element.
    3. the ability to undo/redo based on a resource, because as the focus moves in the workbench, undo/redo will work on the focused resource, and not on the chronological operations. i.e. typing in a.ts, then in b.ts and then moving focus to a.ts and running undo will undo the edits in a.ts and leave the edits in b.ts untouched.

    To prevent disruption, I suggest that any work done here is done via a PR which we can test and merge in only when things work smoothly.

  5. added
    feature-request
    on Feb 26, 2020
  6. mjbvz commented on Mar 10, 2020

    @mjbvz
    ContributorAuthor

    Alexandru Dima (@alexdima) I'm going to look into adopting the UndoRedoService within the model layer of custom editors, similarly to how you've adopted it in TextModel. Will copy you on the PR

  7. mjbvz commented on Mar 13, 2020

    @mjbvz
    ContributorAuthor

    Custom editors are now be using the UndoRedoService. I've also exposed a way for extensions to contribute the label used for changes

  8. 17 remaining items

  9. mjbvz commented on Jun 24, 2020

    @mjbvz
    ContributorAuthor

    Guilherme Caponetto (@caponetto) Which operating system are you on? I see this working as expected on MacOS using a <textarea> inside a custom editor

  10. caponetto commented on Jun 24, 2020

    @caponetto

    Matt Bierner (@mjbvz) Sorry, I meant for the custom editor that I'm working on, which deals with diagram components, not text.
    These operations are working fine (on Fedora 32) for a textarea inside a custom editor.

    I just wonder how can we leverage from these menus on other types of custom editors.
    Currently, Ctrl+C and Ctrl+V are handled by us but Edit->Copy doesn't do anything because we don't have such a handler.

  11. mjbvz commented on Jun 24, 2020

    @mjbvz
    ContributorAuthor

    Guilherme Caponetto (@caponetto) Can you please file a new feature request for that. It sounds like a good use case that will likely require some new APIs for custom editors

    For copy and paste, you could try using the copy event inside the webview

  12. lramos15 commented on Jul 1, 2020

    @lramos15
    Member

    Matt Bierner (@mjbvz) Trying to verify this with the hex editor extension which listens to the undo and redo events which get fired for custom editors. I can execute undo and redo via keyboard shortcut, but not via the command palette. When you mean edit menu do you mean the right click menu?

  13. connor4312 commented on Jul 1, 2020

    @connor4312
    Member

    I was able to test the binary pawdraw editor but undo/redo didn't have an effect in the cat scratch editor. I'm not sure if I'm testing this correctly...

  14. added
    verification-steps-needed
    and removed
    verified
    on Jul 1, 2020
  15. mjbvz commented on Jul 2, 2020

    @mjbvz
    ContributorAuthor

    Logan Ramos (@lramos15) Thanks for testing. This is for the undo/redo commands in the edit menu from the title bar. I've opened #101553 to track the undo/redo command palette not working

  16. mjbvz commented on Jul 2, 2020

    @mjbvz
    ContributorAuthor

    Connor Peet (@connor4312) Were you following #90110 (comment)?

    I just tried on MacOS but see it working properly:

    Jul-01-2020 17-34-57

  17. connor4312 commented on Jul 2, 2020

    @connor4312
    Member

    Yea. Actually testing it some more it looks like can undo, but it's inconsistent, video: https://memes.peet.io/img/20-07-4a124599-3ddf-4c7a-aba0-8313019828bd.webm

    Might an issue with the sample rather than vscode

  18. mjbvz commented on Jul 2, 2020

    @mjbvz
    ContributorAuthor

    I can't repo this not working on windows, even if trying to trigger these actions quickly. Connor Peet (@connor4312) Can you make sure you have the latest extension sample version? Any specific repo steps?

  19. added
    verified
    and removed
    verification-steps-needed
    on Jul 2, 2020
  20. locked and limited conversation to collaborators on Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

custom-editorsfeature-requestundo-redoverification-neededverifiedwebview

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions