jesseduffield / lazygit

simple terminal UI for git commands
MIT License
50.97k stars 1.79k forks source link

Open file with Alt+Click in VSCode integrated terminal #2516

Open gthau opened 1 year ago

gthau commented 1 year ago

Describe the bug My git workflow is the following in VSCode:

VSCode's integrated terminal is able to detect URLs, file paths, and branch names to perform some actions by Alt+clicking on them. E.g. you launch an node.js app and there's a compilation issue, you can see the file path in the terminal output and can Alt+Click it to open the file in Editor Area. Very convenient. I'd like to same to work with lazygit.

Unfortunately, there are 2 issues that prevent it: 1/ lazygit seems to ignore the Alt key when Alt+clicking and always perform its default action (in case of the Files panel, stage/unstage the file clicked) 2/ for files at the root of the directory, VSCode doesn't recognize it as a file path, only where there is a path separator does it recognize it.

Note that if I hover the file path in the Files panel, VSCode shows a hover popup with Open in Editor link which I can click to go to the file. This works fine but is a slow user action. What is missing is the ability to use the significantly faster Alt+Click to open the file.

To Reproduce Steps to reproduce the behavior (see attached Gif)

  1. Open VSCode
  2. open terminal in editor area using the command Terminal: Create New Terminal in Editor Area
  3. launch lazygit
  4. Modify some file at the root of the directory and some other file in (nested) directory so those files appear in lazygit's Files panel
  5. Try to hover the file paths and click VSCode link in the hover popup
  6. Try to Alt+Click the file paths

Expected behavior Alt+Click should open the file VSCode editor area, same as when clicking on the link in the hover popup. Alt+Click should open the file regardless of where it is in the repo directory (at the root or nested)

Screenshots lazygit_vscode_openfile

Version info:

$ lazygit --version
commit=16802a048e0425182f08cf0e9a2bc31480e9a55d, build date=2023-02-01T11:02:43Z, build source=binaryRelease, version=0.37.0, os=linux, arch=amd64, git version=2.30.2

PS: thank you for lazygit, I love it!

mark2185 commented 1 year ago

Sorta kinda related as a possible workaround, have you experimented with using the edit command on files, so that it opens it up in an existing VSCode session?

os:
  editCommand: 'code'
  editCommandTemplate: '{{editor}} --goto -- {{filename}}:{{line}}'

Source.

gthau commented 1 year ago

Sorta kinda related as a possible workaround, have you experimented with using the edit command on files, so that it opens it up in an existing VSCode session?

os:
  editCommand: 'code'
  editCommandTemplate: '{{editor}} --goto -- {{filename}}:{{line}}'

Source.

This is a reasonable workaround, better than using Ctrl+P in VSCode to find my file. Thank you for that.

My setup is a mix mouse-keyboard use. Being able to Alt+Click (same as other interactions in VSCode) would be great. Can those 'os' or customCommands accept "key bindings" with mouse left-right buttons? I couldn't find such examples in the docs.

mark2185 commented 1 year ago

Can those 'os' or customCommands accept "key bindings" with mouse left-right buttons?

As far as I know - no. But I don't know whether it's a technical limitation (i.e. the underlying library) or just an implementation detail (i.e. "nobody ever needed it before").

gthau commented 1 year ago

In my understanding, we don't need to support key bindings with mouse buttons, but lazygit should ignore the clicks if they are performed with a modifier (Control, Alt, Shift, Option): in that case I think the program that hosts the shell will perform its action (in that case, VSCode will handle the opening of the file, not lazygit). Although I'm not sure of it.

In the meantime, modifying the 'os' editCommand provides a good enhancement of the current situation :)

mark2185 commented 1 year ago

we don't need to support key bindings with mouse buttons lazygit should ignore the clicks if they are performed with a modifier (Control, Alt, Shift, Option)

Sounds to me they're two sides of the same coin, in both cases we definitely need to intercept mouse clicks - the question is, what should we do with them? :)

In any case, @jesseduffield might know more.

gthau commented 1 year ago

Looking at the keybindings file: https://github.com/jesseduffield/lazygit/blob/master/pkg/gui/keybindings/keybindings.go It seems MouseLeft, MouseRight, etc. are not supported. However they are supported in gocui and the underlying termbox-go lib so it would be possible to add in lazygit.