vscode-bookmarks icon indicating copy to clipboard operation
vscode-bookmarks copied to clipboard

[FEATURE] - sort bookmarks alphabetically (by filename)

Open PhilipMay opened this issue 3 years ago • 12 comments

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

PhilipMay avatar May 23 '21 04:05 PhilipMay

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

alefragnani avatar May 29 '21 00:05 alefragnani

@alefragnani do you plan to implement this?

PhilipMay avatar Jun 23 '21 21:06 PhilipMay

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

alefragnani avatar Jun 26 '21 14:06 alefragnani

Vote on this feature, it's useful

imageslr avatar May 24 '22 14:05 imageslr

Vote on this feature, it's useful

How and where? Just here with a thubs up?

PhilipMay avatar May 25 '22 13:05 PhilipMay

That's what I count 😬

alefragnani avatar May 25 '22 15:05 alefragnani

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

Thanks :)

imageslr avatar May 28 '22 09:05 imageslr

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 avatar Oct 04 '22 10:10 aisbergde

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

aisbergde avatar Oct 04 '22 13:10 aisbergde

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.

xstar2091 avatar Jan 16 '24 02:01 xstar2091

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.

dimateos avatar Feb 20 '24 15:02 dimateos

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.line - b.line;
        });
    });

    //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();

lenfromkits avatar Apr 13 '24 04:04 lenfromkits