alefragnani / vscode-bookmarks

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

Bookmarks do not get saved when opening files not belonging to a workspace #595

Open elesbb opened 1 year ago

elesbb commented 1 year ago

Hello,

TL;DR: If I don't open the same file in the SAME VS Code window that it was open previously, all bookmarks are lost

I have a text document with notes in, I like to use bookmarks to give me quick ways to navigate to certain things.

If I open the text document using Visual Studio Code, and apply bookmarks, then close the file, and reopen it again (file->open) the bookmarks are gone.

If I open the folder containing the text document as a workspace in Visual Studio Code, then the bookmarks are still there.

If I already have a workspace open, that does NOT contain the text file, open the text file, add bookmarks, close file, reopen file, bookmarks are still there.

If I already have a workspace open, and I do "File: Open Active File in New Window" the bookmarks are gone again.

Is it possible to save ONE location for all bookmarks for all files?? Another option would be each file gets its own file which stores bookmark information in that. When opening a file, extension searches in the "saved_bookmarks" directory for a ".bkms" file. Inside the .bkms file, are the bookmarks which correspond to the (the file currently being loaded/opened.

elesbb commented 1 year ago

After looking at the code, I think I see what is happening.

`async function loadWorkspaceState(): Promise {

    // no workspace, load as `undefined` and will always be from `workspaceState`
    if (!vscode.workspace.workspaceFolders) {   **<- This condition is entered, when I opened the file using "File: Open Active File in New Window". It is passed when I open the file inside an instance of VSCode which has a workspaceFolder associated with it.**
        const ctrl = await loadBookmarks(undefined);
        controllers.push(ctrl);
        activeController = ctrl;
        return;
    }`

This is applicable to the save function as well.

Simply adding a setting to always use one location should fix this. So it would look like this: `async function loadWorkspaceState(): Promise {

    // no workspace, load as `undefined` and will always be from `workspaceState`
    if (!vscode.workspace.workspaceFolders **|| cfg.affectsConfiguration("bookmarks.saveInOneLocation")**) {
        const ctrl = await loadBookmarks(undefined);
        controllers.push(ctrl);
        activeController = ctrl;
        return;
    }`

Make this change in the load and save functions and I think it would work. Then the user can select how/where they want the bookmarks saved. This would be super helpful.