alefragnani / vscode-bookmarks

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

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

Open PhilipMay opened 3 years ago

PhilipMay commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@alefragnani do you plan to implement this?

alefragnani commented 3 years ago

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

imageslr commented 2 years ago

Vote on this feature, it's useful

PhilipMay commented 2 years ago

Vote on this feature, it's useful

How and where? Just here with a thubs up?

alefragnani commented 2 years ago

That's what I count 😬

imageslr commented 2 years ago

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

Thanks :)

aisbergde commented 1 year ago

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 commented 1 year ago

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 commented 8 months ago

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 `

  1. add bookmark "b"
  2. add bookmark "c"
  3. add bookmark "a"
  4. ` 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 commented 7 months ago

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 commented 5 months ago

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