From e322fc86f782210d71b4c3675fc7884c7c2fae67 Mon Sep 17 00:00:00 2001 From: Mattias Eriksson Date: Fri, 2 Feb 2024 15:16:43 +0100 Subject: [PATCH 1/2] Fix some pane focus and find related issues * If a context_page was shown, the focus for the panes didn't work. By clicking all panes you could get input in all of them as long as the context_page prevented focus updated. * Find was drawn in all panes, with typed text being entered in all of them. Changed this to only show find in the focused pane. * Also, when I was going find related stuff, I populate the find entry with selected text, and clear the find search value on close. --- src/main.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3fd74aa..bdbcf88 100644 --- a/src/main.rs +++ b/src/main.rs @@ -367,9 +367,7 @@ impl App { } fn update_focus(&self) -> Command { - if self.core.window.show_context { - Command::none() - } else if self.find { + if self.find { widget::text_input::focus(self.find_search_id.clone()) } else if let Some(terminal_id) = self.terminal_ids.get(&self.pane_model.focus).cloned() { widget::text_input::focus(terminal_id) @@ -883,6 +881,7 @@ impl Application for App { } else if self.find { // Close find if open self.find = false; + self.find_search_value.clear(); } // Focus correct widget @@ -1025,6 +1024,22 @@ impl Application for App { } Message::Find(find) => { self.find = find; + if find { + if let Some(tab_model) = self.pane_model.active() { + let entity = tab_model.active(); + if let Some(terminal) = tab_model.data::>(entity) { + let terminal = terminal.lock().unwrap(); + let term = terminal.term.lock(); + if let Some(text) = term.selection_to_string() { + self.find_search_value = text; + } + } + } else { + log::warn!("Failed to get focused pane"); + } + } else { + self.find_search_value.clear(); + } // Focus correct input return self.update_focus(); @@ -1504,7 +1519,8 @@ impl Application for App { } } - if self.find { + //Only draw find in the currently focused pane + if self.find && pane == self.pane_model.focus { let find_input = widget::text_input::text_input( fl!("find-placeholder"), &self.find_search_value, From 623a193ad46fba84f889f2b411fbed4f5c1a181b Mon Sep 17 00:00:00 2001 From: Mattias Eriksson Date: Fri, 2 Feb 2024 13:56:17 +0100 Subject: [PATCH 2/2] Make context menu work better with panes --- src/main.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index bdbcf88..153fb67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -271,7 +271,7 @@ pub enum Message { TabActivateJump(usize), TabClose(Option), TabContextAction(segmented_button::Entity, Action), - TabContextMenu(segmented_button::Entity, Option), + TabContextMenu(pane_grid::Pane, Option), TabNew, TabPrev, TabNext, @@ -1253,8 +1253,23 @@ impl Application for App { } } } - Message::TabContextMenu(entity, position_opt) => { - if let Some(tab_model) = self.pane_model.active() { + Message::TabContextMenu(pane, position_opt) => { + // Close any existing context menues + let panes: Vec<_> = self.pane_model.panes.iter().collect(); + for (_pane, tab_model) in panes { + let entity = tab_model.active(); + match tab_model.data::>(entity) { + Some(terminal) => { + let mut terminal = terminal.lock().unwrap(); + terminal.context_menu = None; + } + _ => {} + } + } + + // Show the context menu on the correct pane / terminal + if let Some(tab_model) = self.pane_model.panes.get(pane) { + let entity = tab_model.active(); match tab_model.data::>(entity) { Some(terminal) => { // Update context menu position @@ -1264,6 +1279,11 @@ impl Application for App { _ => {} } } + + // Shift focus to the pane / terminal + // with the context menu + self.pane_model.focus = pane; + return self.update_title(Some(pane)); } Message::TabNew => self.create_and_focus_new_terminal(self.pane_model.focus), Message::TabNext => { @@ -1490,7 +1510,7 @@ impl Application for App { match tab_model.data::>(entity) { Some(terminal) => { let mut terminal_box = terminal_box(terminal).id(terminal_id).on_context_menu( - move |position_opt| Message::TabContextMenu(entity, position_opt), + move |position_opt| Message::TabContextMenu(pane, position_opt), ); if self.config.focus_follow_mouse {