alefragnani / vscode-bookmarks

Bookmarks Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks
GNU General Public License v3.0
1.68k stars 163 forks source link

[FEATURE] - Support Undo concept for bookmark commands #499

Closed wbfw109 closed 1 year ago

wbfw109 commented 2 years ago

Environment/version

Steps to reproduce with setting.json "files.autoSave": "off", // (Default) "bookmarks.saveBookmarksInProject": true,

  1. ">bookmarks: Toggle" or ">bookmarks: Toggle Labeled" it automatically create bookmarks.json.
  2. delete this line including "\n\r" it automatically delete bookmarks.json.
  3. Undo (Ctrl+Z). it undo the deleted line but, bookmark was not.

please fix it 👍

alefragnani commented 2 years ago

Hi @wbfw109 ,

Once you delete a bookmarked line, the bookmark is deleted as well. If the current workspace doesn't have any bookmark, the .vscode\bookmarks.json file is deleted as well, because it would be empty anyway, which has no purpose. This behavior was added in #51.

The Undo operation, on the other hand, works as expected. It won't bring back the deleted bookmark, because the extension does not support undo operation for bookmarks. Just like it won't undo any bookmark operation (like toggling or changing its label), when you hit Undo. Looking closer, I don't see VS Code providing any Undo API that I could attach the operations. So, to have such feature, it should be developed completely inside the extension.

Hope this helps

wbfw109 commented 2 years ago

Hi @wbfw109 ,

Once you delete a bookmarked line, the bookmark is deleted as well. If the current workspace doesn't have any bookmark, the .vscode\bookmarks.json file is deleted as well, because it would be empty anyway, which has no purpose. This behavior was added in #51.

The Undo operation, on the other hand, works as expected. It won't bring back the deleted bookmark, because the extension does not support undo operation for bookmarks. Just like it won't undo any bookmark operation (like toggling or changing its label), when you hit Undo. Looking closer, I don't see VS Code providing any Undo API that I could attach the operations. So, to have such feature, it should be developed completely inside the extension.

Hope this helps

I found that saved bookmarks no longer available when file was renamed even though maybe it following git version control system. I've tried directly changing .vscode/bookmarks.json, but it automatically reverts to the old bookmarks file contents.

alefragnani commented 2 years ago

@wbfw109 ,

If you rename/move the file outside VS Code, the bookmarks are not updated. The extension depends entirely on VS Code API/events to do that.

Updating the .vscode/bookmarks.json file manually will take no effect, if you have the relative window open in VS Code. This is not a two-way binding storage. The extension won't keep looking for changes on that file, to update the bookmarks on the fly. Quite the opposite, it is just a storage.

If you need for any reason, update the .vscode/bookmarks.json manually, you have at least two alternatives:

  1. Outside VS Code (using Notepad, vi, etc..)
  2. Opening just that file, instead of the folder/project itself

Just remember to previously close the VS Code instance that refers to that file/project, otherwise it will be overwritten again.

Hope this helps