Gruntfuggly / todo-tree

Use ripgrep to find TODO tags and display the results in a tree view
Other
1.4k stars 135 forks source link

Keyboard shortcuts to navigate to the previous/next tag #719

Closed GitHunter0 closed 1 year ago

GitHunter0 commented 1 year ago

Hey @Gruntfuggly ,

It would be really useful to be able to navigate to the previous or next tag using keyboard shortcuts like Comment Anchors does.

It is the only essential feature I miss in todo-tree, which is overall a great extension.

Thank you

Gruntfuggly commented 1 year ago

This isn't as simple as you might think because the extension doesn't really know anything about where you are in the current file. I'll see what I can come up with though.

GitHunter0 commented 1 year ago

Understood, thanks, I appreciate the effort.

Gruntfuggly commented 1 year ago

Just uploaded a new version with Todo Tree: Go To Next and Todo Tree: Go To Previous which can be bound to whatever keys you want.

Let me know if it works as expected.

GitHunter0 commented 1 year ago

@Gruntfuggly, thanks man, this is really helpful.

The only thing I expected to be different is that the cursor is not being positioned right in the beginning of the tag line but in the last line before the next tag.

Here's an example, I configured #%% as a tag and I expected the cursor to go from section 1 to section 2. Instead, it's going from section 1 to last line: todo-tree

Gruntfuggly commented 1 year ago

Can you post your config so I can try it out?

GitHunter0 commented 1 year ago

Sure, this my user settings.json part:

    "todo-tree.tree.buttons.export": true,
    "todo-tree.tree.scanMode": "current file",
    "todo-tree.tree.showBadges": false,
    "todo-tree.tree.buttons.scanMode": true,
    "todo-tree.tree.showScanModeButton": true,
    "todo-tree.general.tags": [
        "#%%",
        "#%%%",
        "#%%%%",
        "#%%%%%"
    ],
Gruntfuggly commented 1 year ago

Actaully - can you post a section of the code too (sorry - should have asked yesterday!) What sort of file is it?

GitHunter0 commented 1 year ago

No problem @Gruntfuggly , it's just a python file (a text file with .py extension), for example test.py:


#%% section 1

#%%% subsection 1

#%%% subsection 2

#%% section 2

# line 1
# line 2

import numpy as np
import pandas as pd

# last line

#%% section 3
Gruntfuggly commented 1 year ago

Sorry - I think I'll need your regex setting too.

GitHunter0 commented 1 year ago

No problem @Gruntfuggly, but I don't know what regex setting you are referring to, where can I find that?

Gruntfuggly commented 1 year ago

I can't get it to do what you're seeing, but I have noticed one thing -yYour configuration is not really using much of the regex - it matches the start of line character. I can make it work properly by just removing the |^ from the regex and then changing your tags: e.g.

    "todo-tree.regex.regex": "(//|#|<!--|;|/\\*|^[ \\t]*(-|\\d+.))\\s*($TAGS)",
    "todo-tree.general.tags": [
        "%%",
        "%%%",
        "%%%%",
        "%%%%%"
    ],

Now it matches the # as the comment character and the the tag is the bit that follows.

I'll see if I can make it work more sensibly with your original configuration though.

GitHunter0 commented 1 year ago

I'll see if I can make it work more sensibly with your original configuration though.

I appreciate that, because %% is an operator in Python and should not be interpreted as a tag, so I will really need the # in the tags.

Gruntfuggly commented 1 year ago

Do you use any other tags? If not, you could simplify the regex down to

 "todo-tree.regex.regex": "#($TAGS)",

which would only match your tags if they were preceded by the hash.

GitHunter0 commented 1 year ago

Thank you @Gruntfuggly, your workaround is working fine! I don't use other tags at the moment.

Gruntfuggly commented 1 year ago

OK - I think I have a fix for your original configuration too! 8-)