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

[FEATURE] - sort bookmarks alphabetically (by filename) #435

Open
PhilipMay opened this issue May 23, 2021 · 12 comments
Open

[FEATURE] - sort bookmarks alphabetically (by filename) #435

PhilipMay opened this issue May 23, 2021 · 12 comments

Comments

@PhilipMay
Copy link

When I show the bookmarks it would be nice to have an option to show them in alphabetical order (of the filename).

See screenshot where this is not the case and it would be much easier to find the bookmarrks if they would be in alphabetical order.

image

Could you maybe add this option?

Many thanks
Philip

@alefragnani
Copy link
Owner

Hi @PhilipMay ,

Yep, it is doable. Right now it doesn’t do any sort at all. It’s just the order of bookmark toggles.

Thanks for your suggestion

@PhilipMay
Copy link
Author

@alefragnani do you plan to implement this?

@alefragnani
Copy link
Owner

@PhilipMay Yep, it's definitely on the table, but no ETA yet.

@alefragnani alefragnani changed the title [FEATURE] - sort bookmarks alphabetically [FEATURE] - sort bookmarks alphabetically (by filename) Jun 30, 2021
@imageslr
Copy link

Vote on this feature, it's useful

@PhilipMay
Copy link
Author

Vote on this feature, it's useful

How and where? Just here with a thubs up?

@alefragnani
Copy link
Owner

That's what I count 😬

@imageslr
Copy link

Oh BTW,I want to sort by label name instead of filename.

Thanks :)

@aisbergde
Copy link

It looks like this has low priority.
As workaround, I installed https://marketplace.visualstudio.com/items?itemName=fvclaus.sort-json-array
And then from time to time I use "sort JSON array ascending" and then "path"
It would be nice to have this kind of action implemented directly in the bookmarks extension, doing this resorting without the need of an additional extension.

@aisbergde
Copy link

But unfortunately, changes made to bookmarks.json cannot simply be read in. You have to restart VSC for changes to be applied.

It would be very helpful if this button would read the bookmarks.json. At the moment, I don't understand what this button does at all:
image

@xstar2091
Copy link

Hi @PhilipMay ,

Yep, it is doable. Right now it doesn’t do any sort at all. It’s just the order of bookmark toggles.

Thanks for your suggestion

Hi @alefragnani

It is not really in my opinion. In my vscode the bookmarks are sorted by line num. For example, I toggle bookmarks at line 37, line 31, line 35
31. add bookmark "b" 32. 33. 34. 35. add bookmark "c" 36. 37. add bookmark "a" 38.
I add bookmark "a" at line 37 first, then add bookmark "b", and last add bookmark "c"

But the bookmarks shown in my vscode is
bookmark "b" (Ln 31, Col 1)
bookmark "c" (Ln 35, Col 1)
bookmark "a"(Ln 37, Col 1)

They are sorted by line numbers.

Could you maybe add an option that sorted by added sequence? In this example, the bookmarks would be shown as
bookmark "a"(Ln 37, Col 1)
bookmark "b" (Ln 31, Col 1)
bookmark "c" (Ln 35, Col 1)

In this scenario, bookmarks are shown in stack sequence would help code reading.

@dimateos
Copy link

Would love a simple alphabetical sorting. I tend to prefix things to kind of group them:

image

Sorting would be the simplest way of grouping them visually without any extra folding features.

@lenfromkits
Copy link

lenfromkits commented Apr 13, 2024

This is, in my opinion, a critical feature if someone intends to use Bookmarks for real. I can't scan the list of files or labels every single time I want to use a bookmark. This renders bookmarks useless to me other then to set temporary bookmarks and blow away all bookmarks every time I want to start a new set of actions that use bookmarks.

Here's a node Js file for a workaround. It's a PIA though:
(thanks @aisbergde above for the idea)

//Requires Node.js.
//Save it in the project root folder next to the .vscode folder.
//Name it sortBookmarks.js
//Run it by calling "node sortBookmarks.js" from the command line
//Then you have to completely restart VS Code to see the changes.
const fs = require('fs');
const path = require('path');
const bookmarks = require('./.vscode/bookmarks.json');
function SortFile(){

    //first sort the file names
    let files = bookmarks.files;
    let sortedFiles = files.sort((a, b) => {
        let pathA = a.path;
        let pathB = b.path;

        //get just the file name from the path
        let nameA = pathA.substring(pathA.lastIndexOf('/') + 1);
        let nameB = pathB.substring(pathB.lastIndexOf('/') + 1);

        return nameA.localeCompare(nameB);
    });

    //now sort the bookmarks within each file
    sortedFiles.forEach(file => {
        let fileBookmarks = file.bookmarks;
        file.bookmarks = fileBookmarks.sort((a, b) => {
             return a.label.localeCompare(b.label);
        });
    });

    //write the sorted bookmarks back to the file in a pretty format
    let bookmarksPath = './.vscode/bookmarks.json';
    fs.writeFileSync(bookmarksPath, JSON.stringify(bookmarks, null, 4));
}

SortFile();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants