From 85409e57a32b742df9cffb27ca234fb5e939bbec Mon Sep 17 00:00:00 2001 From: mgpinf Date: Mon, 24 Feb 2025 04:07:09 +0530 Subject: [PATCH] Option to disable attributes for non matching text in quick select mode (#6683) * feat: optionally disable non-matching text attributes in Quick Select Add a configuration option 'disable_attributes_for_non_matching_text_in_quick_select' that disables all attributes for non-matching text in Quick Select Mode. The default value for 'disable_attributes_for_non_matching_text_in_quick_select' is false This resolves the issue https://github.com/wezterm/wezterm/issues/4022 * docs: documentation for disabling attributes for non matching text in QuickSelect Add documentation for the below configuration option: - `disable_attributes_for_non_matching_text_in_quick_select` * feat: display quick select label and match in bold * refactor: fetch colors from existing reference to config * fix: reset additional attributes for non matching text Reset additional below mentioned attributes to default for non matching text if the configuration option disable-attributes-for-non-matching-text-in-quick-select-mode is true - Italic - Blink - StrikeThrough - Invisible - Hyperlink * fix: update attributes to reset * feat: add reset_attributes function in termwiz cell Add reset_attributes function in termwiz cell Use the above function to reset cell attributes for the cell * refactor: update method name to clear_attributes * termwiz: update version because public method has been added Update termwiz version because a new method 'reset_attributes' has been added in termwiz/src/cell.rs * fix: update get_lines method in quickselect to be same as with_lines_mut * termwiz: simpler method name, implementation to clear cell attributes Use simpler method name and implementation as per suggestion https://github.com/wezterm/wezterm/pull/6683#discussion_r1966596988 * refactor: clear cell attributes for every line if flag is set Clear attributes for every line if the configuration option disable-attributes-for-non-matching-text-in-quick-select has been set Partially implement changes mentioned in suggestion https://github.com/wezterm/wezterm/pull/6683#discussion_r1966597826 * refactor: replace for loop with for_each method to iterate through cells Partially implement changes mentioned in suggestion https://github.com/wezterm/wezterm/pull/6683#discussion_r1966597826 * refactor: rename configuration option to quick_select_remove_styling Rename option to remove styling in quick select from 'disable_attributes_for_non_matching_text_in_quick_select' to 'quick_select_remove_styling' Implement changes mentioned in suggestion https://github.com/wezterm/wezterm/pull/6683#discussion_r1966598496 * fix: remove bold attribute when displaying quick select label, match This is in order to raise this in a separate PR Suggestion mentioned here https://github.com/wezterm/wezterm/pull/6683#issuecomment-2676394535 * docs: update documentation for quick_select_remove_styling * termwiz: just bump minor part Since the only change in termwiz is addition of a public method, it should be forward compatible, so we can just bump the minor part Apply changes mentioned in suggestion https://github.com/wezterm/wezterm/pull/6683#discussion_r1966600258 * fix: clear attributes for each cell in all lines in get_lines method Apply changes mentioned in suggestion https://github.com/wezterm/wezterm/pull/6683#discussion_r1966848308 * fix: clear appdata for line after clearing attributes of each cell Move call to clear appdata for line after the call to clear attributes from each cell when configuration option 'quick_select_remove_styling' is enabled Apply changes mentioned in suggestion https://github.com/wezterm/wezterm/pull/6683#discussion_r1966848015 --- Cargo.lock | 2 +- config/src/config.rs | 2 ++ .../lua/config/quick_select_remove_styling.md | 13 +++++++++++++ docs/quickselect.md | 10 ++++++++++ termwiz/Cargo.toml | 2 +- termwiz/src/cell.rs | 5 +++++ wezterm-gui/src/overlay/quickselect.rs | 16 +++++++++++++++- 7 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 docs/config/lua/config/quick_select_remove_styling.md diff --git a/Cargo.lock b/Cargo.lock index 4e7128bd7..36e05f226 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5518,7 +5518,7 @@ checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" [[package]] name = "termwiz" -version = "0.23.0" +version = "0.23.1" dependencies = [ "anyhow", "base64 0.22.1", diff --git a/config/src/config.rs b/config/src/config.rs index 6c93b4805..21522f4a3 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -420,6 +420,8 @@ pub struct Config { pub quick_select_patterns: Vec, #[dynamic(default = "default_alphabet")] pub quick_select_alphabet: String, + #[dynamic(default)] + pub quick_select_remove_styling: bool, #[dynamic(default)] pub mouse_bindings: Vec, diff --git a/docs/config/lua/config/quick_select_remove_styling.md b/docs/config/lua/config/quick_select_remove_styling.md new file mode 100644 index 000000000..c0b373db0 --- /dev/null +++ b/docs/config/lua/config/quick_select_remove_styling.md @@ -0,0 +1,13 @@ +--- +tags: + - quick_select +--- +# `quick_select_remove_styling = false` + +{{since('nightly')}} + +When set to `true`, all color and styling is removed from the pane prior to performing matching and highlighting any matching text in quick select mode. + +This can make it easier to focus on the matches, particularly when the pane already had a lot of styling and colors. + +Defaults to `false` diff --git a/docs/quickselect.md b/docs/quickselect.md index ee76b8739..5b1219183 100644 --- a/docs/quickselect.md +++ b/docs/quickselect.md @@ -28,3 +28,13 @@ text, and cancel quick select mode. Pressing `ESCAPE` will cancel quick select mode. ![Screenshot demonstrating the quickselect text highlights](screenshots/wezterm-quick-select.png) + +{{since('nightly')}} + +A configuration option [quick_select_remove_styling](config/lua/config/quick_select_remove_styling.md) +has been added which when set to `true`, results in all color and styling +being removed from the pane prior to performing matching and highlighting +any matching text in quick select mode. + +This can make it easier to focus on the matches, particularly when the pane +already had a lot of styling and colors. diff --git a/termwiz/Cargo.toml b/termwiz/Cargo.toml index 51a38f058..56e610492 100644 --- a/termwiz/Cargo.toml +++ b/termwiz/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Wez Furlong"] name = "termwiz" -version = "0.23.0" +version = "0.23.1" edition = "2018" repository = "https://github.com/wezterm/wezterm" description = "Terminal Wizardry for Unix and Windows" diff --git a/termwiz/src/cell.rs b/termwiz/src/cell.rs index de783b22a..f9bab4234 100644 --- a/termwiz/src/cell.rs +++ b/termwiz/src/cell.rs @@ -375,6 +375,11 @@ impl CellAttributes { self.background.into() } + /// Clear all attributes from a cell + pub fn clear(&mut self) { + *self = Self::blank(); + } + fn allocate_fat_attributes(&mut self) { if self.fat.is_none() { self.fat.replace(Box::new(FatAttributes { diff --git a/wezterm-gui/src/overlay/quickselect.rs b/wezterm-gui/src/overlay/quickselect.rs index 728850cd3..428fa4666 100644 --- a/wezterm-gui/src/overlay/quickselect.rs +++ b/wezterm-gui/src/overlay/quickselect.rs @@ -545,7 +545,9 @@ impl Pane for QuickSelectOverlay { fn with_lines_mut(&mut self, first_row: StableRowIndex, lines: &mut [&mut Line]) { let mut overlay_lines = vec![]; - let colors = self.renderer.config.resolved_palette.clone(); + let config = &self.renderer.config; + let colors = config.resolved_palette.clone(); + let disable_attr = config.quick_select_remove_styling; // Process the lines; for the search row we want to render instead // the search UI. @@ -553,6 +555,12 @@ impl Pane for QuickSelectOverlay { for (idx, line) in lines.iter_mut().enumerate() { let mut line: Line = line.clone(); + if disable_attr { + line.cells_mut_for_attr_changes_only() + .iter_mut() + .for_each(|cell| cell.attrs_mut().clear()); + line.clear_appdata(); + } let stable_idx = idx as StableRowIndex + first_row; self.renderer.dirty_results.remove(stable_idx); if stable_idx == self.search_row { @@ -633,12 +641,18 @@ impl Pane for QuickSelectOverlay { let (top, mut lines) = self.delegate.get_lines(lines); let colors = renderer.config.resolved_palette.clone(); + let disable_attr = renderer.config.quick_select_remove_styling; // Process the lines; for the search row we want to render instead // the search UI. // For rows with search results, we want to highlight the matching ranges let search_row = renderer.compute_search_row(); for (idx, line) in lines.iter_mut().enumerate() { + if disable_attr { + line.cells_mut_for_attr_changes_only() + .iter_mut() + .for_each(|cell| cell.attrs_mut().clear()); + } let stable_idx = idx as StableRowIndex + top; renderer.dirty_results.remove(stable_idx); if stable_idx == search_row { -- 2.51.2