diff options
author | Christian Duerr <contact@christianduerr.com> | 2020-11-13 05:40:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-13 08:40:09 +0300 |
commit | 9a7844987693909925b8663d8aa905231d291410 (patch) | |
tree | e99b99bcbd0fc40aa1938fc203357321ec024777 /alacritty/src/display.rs | |
parent | b6d94e7b13eb9a14edea843a79c6d86b5b6d8803 (diff) | |
download | r-alacritty-9a7844987693909925b8663d8aa905231d291410.tar.gz r-alacritty-9a7844987693909925b8663d8aa905231d291410.tar.bz2 r-alacritty-9a7844987693909925b8663d8aa905231d291410.zip |
Add ability to select text during search
This removes the restriction of not being able to select text while the
search is active, making it a bit less jarring of a UX when the user
tries to interact with the terminal during search.
Since the selection was used during vi-less search to highlight the
focused match, there is now an option for a focused match color, which
uses the inverted normal match color by default. This focused match is
used for both search modes.
Other mouse interactions are now also possible during search, like
opening URLs or clicking inside of mouse mode applications.
Diffstat (limited to 'alacritty/src/display.rs')
-rw-r--r-- | alacritty/src/display.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/alacritty/src/display.rs b/alacritty/src/display.rs index 6d683336..af21001e 100644 --- a/alacritty/src/display.rs +++ b/alacritty/src/display.rs @@ -27,7 +27,7 @@ use crossfont::{self, Rasterize, Rasterizer}; use alacritty_terminal::event::{EventListener, OnResize}; use alacritty_terminal::index::{Column, Direction, Point}; use alacritty_terminal::selection::Selection; -use alacritty_terminal::term::{RenderableCell, SizeInfo, Term, TermMode}; +use alacritty_terminal::term::{SizeInfo, Term, TermMode}; use alacritty_terminal::term::{MIN_COLS, MIN_SCREEN_LINES}; use crate::config::font::Font; @@ -437,7 +437,13 @@ impl Display { mods: ModifiersState, search_state: &SearchState, ) { - let grid_cells: Vec<RenderableCell> = terminal.renderable_cells(config).collect(); + // Convert search match from viewport to absolute indexing. + let search_active = search_state.regex().is_some(); + let viewport_match = search_state + .focused_match() + .and_then(|focused_match| terminal.grid().clamp_buffer_range_to_visible(focused_match)); + + let grid_cells = terminal.renderable_cells(config, !search_active).collect::<Vec<_>>(); let visual_bell_intensity = terminal.visual_bell.intensity(); let background_color = terminal.background_color(); let cursor_point = terminal.grid().cursor.point; @@ -471,7 +477,21 @@ impl Display { self.renderer.with_api(&config.ui_config, config.cursor, &size_info, |mut api| { // Iterate over all non-empty cells in the grid. - for cell in grid_cells { + for mut cell in grid_cells { + // Invert the active match in vi-less search. + let cell_point = Point::new(cell.line, cell.column); + if cell.is_match + && viewport_match + .as_ref() + .map_or(false, |viewport_match| viewport_match.contains(&cell_point)) + { + let colors = config.colors.search.focused_match; + let match_fg = colors.foreground().color(cell.fg, cell.bg); + cell.bg = colors.background().color(cell.fg, cell.bg); + cell.fg = match_fg; + cell.bg_alpha = 1.0; + } + // Update URL underlines. urls.update(size_info.cols(), &cell); @@ -525,7 +545,7 @@ impl Display { } if let Some(message) = message_buffer.message() { - let search_offset = if search_state.regex().is_some() { 1 } else { 0 }; + let search_offset = if search_active { 1 } else { 0 }; let text = message.text(&size_info); // Create a new rectangle for the background. |