visual-studio-codevscode-extensions

what exactly undoStopAfter and undoStopBefore options in edit method mean how do they behave


edit method on TextEditor of Vs Code Api

e.edit((editBuilder) =>{//here e is an object of texteditor 
            editBuilder.insert(_p, content);
            return true;
        },
        {undoStopAfter : true ,undoStopBefore : false}
    ).then(x=>{
       // what will happen after specifying undoStopAfter and undoStopBefore options?
            return true;
        });

Solution

  • They specify if an "undo stop" should be inserted before and after the document change (in this case an edit) is executed. An "undo stop" is like a checkpoint you access when using ctrl+z/ctrl+y. If both are set to false, then the edit will practically be part of the previous edit in the otherwise inaccessible history stack that vscode uses.

    See my question and answer here for an example of a use-case.

    By default it seems like edit adds an "undo stop" before an edit (undoStopAfter : true), but it is ambiguous if it adds one after an edit.