Move cursor on mouse click via kitty's OSC 133 click_events=1 #10932
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Move cursor on mouse click via kitty's OSC 133 click_events=1
When the user clicks somewhere in the prompt, kitty asks the shell
to move the cursor there (since there is not much else to do).
This is currently implemented by sending an array of
forward-char-passive commands. This has problems, for example it
is really slow on large command lines (probably because we repaint
everytime).
Implement kitty's
click_events=1flag to set theposition directly. To convert from terminal-coordinates
to fish-coordinates, query CSI 6 n Report Cursor
Position
and use it to compute the left prompt's terminal-coordinates (which
are (0, 0) in fish-coordinates).
Unfortunately this doesn't work correctly while the terminal is
scrolled. This is probably because the cursor position is wrong
if off-screen. To fix that we could probably record the cursor
position while not scrolled, but it doesn't seem terribly important
(the existing implementation also doesn't get it right).
Also add parsing for some unused mouse events; I'll probably remove
them again unless we can use them now.
Future work:
Knowledge of the position of the prompt will
also enable us to make ctrl-l scroll instead of erasing
We still turn off mouse reporting. If we turned it on, it
would be harder to select text in the terminal itself (not fish).
This would typically mean that mouse-drag will alter fish's
selection and shift+mouse-drag or alt+mouse-drag can be used.
To improve this, we could try to synchronize the selection:
if parts of the fish commandline are selected in the terminal's
selection, copy that to fish's selection and vice versa.
Or maybe there is an intuitive criteria, like: whenever we receive
a mouse event outside fish, turn off mouse reporting, and turn
it back on whenver we receive new keyboard input. One problem
is that we lose one event (though we could send it back to the
terminal). Another problem is we would turn it back on too late
in some scenarios.