tmux: Fix edge cases in paragraph text-object

Also add comments explaining the history & pane position checks in the
C-y and C-e bindings, since I used those and had to rethink about what
they're doing.
This commit is contained in:
2024-07-04 15:33:28 +02:00
parent b0b0a2ebea
commit 4e8ab80c66

View File

@@ -176,11 +176,19 @@ bind -T copy-mode-vi i \
}{ if -F "#{==:%1,p}" {
# send "{j0o}k$"
send -X previous-paragraph
send -X cursor-down
# don't move down if we're at the very first
# paragraph
if -F "#{||:#{e|<:#{scroll_position},#{history_size}},#{e|>:#{copy_cursor_y},#{scroll_region_upper}}}" {
send -X cursor-down
}
send -X start-of-line
send -X other-end
send -X next-paragraph
send -X cursor-up
# don't move up if we're at the very last
# paragraph
if -F "#{||:#{e|>:#{scroll_position},0},#{e|<:#{copy_cursor_y},#{scroll_region_lower}}}" {
send -X cursor-up
}
send -X end-of-line
}{ if -F '#{==:%1,"}' {
send -X jump-to-backward '"'
@@ -201,16 +209,20 @@ bind -T copy-mode-vi i \
# scrolling when the respective line is visible. This mimics the behaviour of
# vim's C-y at the top of the file.
bind -T copy-mode-vi C-e \
# check that there is still history beneath to scroll to.
if -F "#{e|>:#{scroll_position},0}" {
send-keys -X scroll-down
# check that the cursor is not at the top of the pane
if -F "#{e|>:#{copy_cursor_y},#{scroll_region_upper}}" {
send-keys -X cursor-up
}
}
bind -T copy-mode-vi C-y \
# check that there is still history above to scroll to.
if -F "#{e|<:#{scroll_position},#{history_size}}" {
send-keys -X scroll-up
# check that the cursor is not at the bottom of the pane
if -F "#{e|<:#{copy_cursor_y},#{scroll_region_lower}}" {
send-keys -X cursor-down
}