Add "scroll caching" functionality, similar to mark jumping in iTerm2 #626
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.
Ok I think this is ready for review again. It's more complicated but a lot more robust. I suspect you'll want to put this behind a checkbox setting?
So, from the top: Adds two new keyboard shortcuts (
ctrl-up/down
) for jumping up/down between previous command executions on the shell.I had to hook into a terminal's scrollbar value-changed signal to handle tracking of the current "location" when the user scrolls.
To detect "command execution", I had to do some relatively hacky stuff. Firstly, like in iTerm2 (AFAIK the only other terminal emulator that supports this?), I had to add a special hidden char to my shell's
PS1
prompt. I opted for the whitespace rendered Soft Hyphen (\u00AD), like this in my .bashrc:Now, I capture the
\r
character with the VTE terminal's on-commit signal. In order to function in the scenario where a command spans multiple lines, I search backwards in the terminal text until I hit the top of the window or find the prompt string ($\xad
). I guess making this string a customiseable option would be a good idea?All of these signals go into the ScrollCache class that handles all of the logic. It stores a cache of cursor positions, populated every time a command is executed from the shell prompt via
\r
.Special consideration is required for a number of cases:
clear/reset
is called, more book keeping is required between the scroll bar and VTE terminal position.Overall from testing I think it's working as expected now. I tested with/without infinite scroll, with mouse wheel scrolling, with clear/reset, with vim, with nvim, with another fullscreen terminal application, with fzf. Some fullscreen terminal applications end up erasing the cache history, but I think that's unavoidable.
Looking forward to feedback, I'll continue dogfooding this myself.
edit: I should note I tried a solution that also uses the hidden prompt character but instead uses the VTE built in search functions to jump up and down. This is super robust to any kind of terminal output/programs, but a bit jankier. It creates a whitespace highlight you can't get rid of easily, doesn't reset properly when you scroll and also doesn't put the line at the top of the terminal. So less fragile but clunkier.