From a0fbb8dea74e07c3bccf00c73254eec1090598a9 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 7 Mar 2018 11:06:23 +0100 Subject: [PATCH] Redraw vi cursor if tmux pane focus changes Fixes #4788. --- share/functions/__fish_config_interactive.fish | 14 ++++++++++++++ share/functions/__fish_shared_key_bindings.fish | 10 ++++++++++ share/functions/fish_default_key_bindings.fish | 5 ----- share/functions/fish_vi_cursor.fish | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index f58ba1faa..b43d5d3a4 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -234,6 +234,20 @@ function __fish_config_interactive -d "Initializations that should be performed __fish_enable_bracketed_paste end + # Similarly, enable TMUX's focus reporting when in tmux. + # This will be handled by + # - The keybindings (reading the sequence and triggering an event) + # - Any listeners (like the vi-cursor) + if set -q TMUX + function __fish_enable_focus --on-event fish_postexec + echo \e\[\?1004h + end + function __fish_disable_focus --on-event fish_preexec + echo \e\[\?1004l + end + __fish_enable_focus + end + function __fish_winch_handler --on-signal WINCH -d "Repaint screen when window changes size" commandline -f repaint >/dev/null 2>/dev/null end diff --git a/share/functions/__fish_shared_key_bindings.fish b/share/functions/__fish_shared_key_bindings.fish index 0ab3b7827..29d7894a8 100644 --- a/share/functions/__fish_shared_key_bindings.fish +++ b/share/functions/__fish_shared_key_bindings.fish @@ -107,6 +107,16 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod bind --preset $argv \ee edit_command_buffer bind --preset $argv \ev edit_command_buffer + + # Tmux' focus events. + # Exclude paste mode because that should get _everything_ literally. + for mode in (bind --list-modes | string match -v paste) + # We only need the in-focus event currently (to redraw the vi-cursor). + bind -M $mode \e\[I 'emit fish_focus_in' + bind -M $mode \e\[O false + bind -M $mode \e\[\?1004h false + end + # Support for "bracketed paste" # The way it works is that we acknowledge our support by printing # \e\[?2004h diff --git a/share/functions/fish_default_key_bindings.fish b/share/functions/fish_default_key_bindings.fish index 941477552..f3ac78349 100644 --- a/share/functions/fish_default_key_bindings.fish +++ b/share/functions/fish_default_key_bindings.fish @@ -84,11 +84,6 @@ function fish_default_key_bindings -d "Default (Emacs-like) key bindings for fis bind --preset $argv \ed kill-word - # Ignore some known-bad control sequences - # https://github.com/fish-shell/fish-shell/issues/1917 - bind --preset $argv \e\[I 'begin;end' - bind --preset $argv \e\[O 'begin;end' - # term-specific special bindings switch "$TERM" case 'rxvt*' diff --git a/share/functions/fish_vi_cursor.fish b/share/functions/fish_vi_cursor.fish index d503f934f..27d2474f3 100644 --- a/share/functions/fish_vi_cursor.fish +++ b/share/functions/fish_vi_cursor.fish @@ -107,7 +107,7 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes' or set -g fish_cursor_unknown block blink echo " - function fish_vi_cursor_handle --on-variable fish_bind_mode --on-event fish_postexec + function fish_vi_cursor_handle --on-variable fish_bind_mode --on-event fish_postexec --on-event fish_focus_in set -l varname fish_cursor_\$fish_bind_mode if not set -q \$varname set varname fish_cursor_unknown