properly restore last pane after invoking fingers

This commit is contained in:
Jorge Morante 2024-03-08 13:31:32 +01:00
parent a30f2fb566
commit 4ba2ec3125
2 changed files with 17 additions and 3 deletions

View File

@ -26,9 +26,11 @@ module Fingers::Commands
class Start < Base class Start < Base
@original_options : Hash(String, String) = {} of String => String @original_options : Hash(String, String) = {} of String => String
@last_pane_id : String | Nil
def run def run
track_options_to_restore! track_options_to_restore
track_last_pane
show_hints show_hints
if Fingers.config.benchmark_mode == "1" if Fingers.config.benchmark_mode == "1"
@ -40,7 +42,7 @@ module Fingers::Commands
teardown teardown
end end
private def track_options_to_restore! private def track_options_to_restore
options_to_preserve.each do |option| options_to_preserve.each do |option|
value = tmux.get_global_option(option) value = tmux.get_global_option(option)
@original_options[option] = value @original_options[option] = value
@ -53,6 +55,16 @@ module Fingers::Commands
end end
end end
private def restore_last_pane
tmux.select_pane(@last_pane_id)
tmux.select_pane(target_pane.pane_id)
end
private def track_last_pane
last_pane_id = tmux.exec("display-message -t '{last}' -p '\#{pane_id}'").chomp
@last_pane_id = last_pane_id unless last_pane_id.empty?
end
private def options_to_preserve private def options_to_preserve
%w[prefix prefix2] %w[prefix prefix2]
end end
@ -94,7 +106,9 @@ module Fingers::Commands
tmux.swap_panes(fingers_pane_id, target_pane.pane_id) tmux.swap_panes(fingers_pane_id, target_pane.pane_id)
tmux.kill_pane(fingers_pane_id) tmux.kill_pane(fingers_pane_id)
restore_last_pane
restore_options restore_options
view.run_action if state.result view.run_action if state.result
end end

View File

@ -283,7 +283,7 @@ class Tmux
exec(Process.quote(["display-message", "-d", delay.to_s, msg])) exec(Process.quote(["display-message", "-d", delay.to_s, msg]))
end end
private def exec(cmd) def exec(cmd)
@sh.exec("#{tmux} #{cmd}") @sh.exec("#{tmux} #{cmd}")
end end
end end