oleg-shilo / codemap.vscode

Code map (syntax tree) of the active document
MIT License
84 stars 28 forks source link

Show current location of cursor in file #29

Closed arnoudplantinga closed 3 years ago

arnoudplantinga commented 4 years ago

Issue Type: Feature Request

It would be helpful to highlight in the codemap the current location of the cursor in the file.

oleg-shilo commented 4 years ago

I will check but it might be harder than it seems. AFAIR the intercepting the caret location change is problematic. Yes VSCode UI model is extremely limited. At least it was when CodeMap was developed. But even standard thing like a custom tooltip over a treeview item is still impossible with VSCode.

oleg-shilo commented 4 years ago

As I was afraid VSCode just does not have an event that can be used by the extensions to detect the caret position change: https://code.visualstudio.com/api/references/vscode-api.

I will still keep this issue open so when/if VSCode gains the required event interface the requested feature will be implemented.

MagTun commented 4 years ago

I wanted to request the same feature, too bad it's not yet possible.

Maybe a work around could be to use markers in the scroll bar of the editor for each codemap title (like the search or the debug do), with maybe a hover popup to know which marker correspond to which title...

oleg-shilo commented 4 years ago

Getting the code from the caret position is not a problem. It can be done even easier than analyzing the scrollbar.

The problem is that VSCode API does not have an event for caret position change. Thus it's not possible to detect when a new treeview node needs to be selected.

But... it can be done manually. Thus I have just released the v1.13.0 that has a command for revealing the tree view node that corresponds to the code at the current caret position in the active document.

The command can be executed either via Alt+L or a button at the top of the CodeMap view:

image

AlencarGabriel commented 4 years ago

Hello @oleg-shilo ,

I found a solution so that I no longer need to use the button.

Just use the event vscode.window.onDidChangeTextEditorSelection.

Whenever the course is moved, this event is triggered.

MagTun commented 4 years ago

@AlencarGabriel, how did you use this event? Which file did you edit? Thanks!

AlencarGabriel commented 4 years ago

I did a test using this approach:

image

The editor variable contains the necessary attributes to identify the user's selection.

oleg-shilo commented 4 years ago

Thanks, will test it and add "auto track location" as an option.

oleg-shilo commented 4 years ago

Done.

Implemented in Release v1.14.0.

Thank you for your contribution.

AlencarGabriel commented 4 years ago

Wonder @oleg-shilo ,

worked perfectly. Glad to have helped!