Make flash highlight autosuggestion on failed deletion

This commit is contained in:
kerty 2025-01-22 22:34:38 +03:00 committed by Johannes Altmanninger
parent bffbf0cd57
commit 6a9f1b925d
2 changed files with 17 additions and 3 deletions

View File

@ -23,7 +23,7 @@ Interactive improvements
Such a malicious file can still potentially insert arbitrary text into the command line but can no longer execute it directly (:issue:`10987`). Such a malicious file can still potentially insert arbitrary text into the command line but can no longer execute it directly (:issue:`10987`).
- The history search now preserves ordering between :kbd:`ctrl-s` forward and :kbd:`ctrl-r` backward searches. - The history search now preserves ordering between :kbd:`ctrl-s` forward and :kbd:`ctrl-r` backward searches.
- Left mouse click now can select pager items. - Left mouse click now can select pager items.
- Instead of flashing all the text to the left of the cursor, fish now flashes the matched token during history token search, the completed token during completion (:issue:`11050`), and the full command line in all other cases. - Instead of flashing all the text to the left of the cursor, fish now flashes the matched token during history token search, the completed token during completion (:issue:`11050`), the autosuggestion when deleting it, and the full command line in all other cases.
New or improved bindings New or improved bindings
^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -507,6 +507,9 @@ pub struct ReaderData {
/// The time when the last flash() completed. /// The time when the last flash() completed.
last_flash: Option<Instant>, last_flash: Option<Instant>,
/// Whether flash autosuggestion.
flash_autosuggestion: bool,
/// The representation of the current screen contents. /// The representation of the current screen contents.
screen: Screen, screen: Screen,
@ -1163,6 +1166,7 @@ impl ReaderData {
reset_loop_state: Default::default(), reset_loop_state: Default::default(),
first_prompt: true, first_prompt: true,
last_flash: Default::default(), last_flash: Default::default(),
flash_autosuggestion: false,
screen: Screen::new(), screen: Screen::new(),
cursor_position_wait: CursorPositionWait::None, cursor_position_wait: CursorPositionWait::None,
input_data, input_data,
@ -1632,7 +1636,14 @@ impl<'a> Reader<'a> {
colors.splice( colors.splice(
pos..pos, pos..pos,
vec![ vec![
HighlightSpec::with_fg(HighlightRole::autosuggestion); if self.flash_autosuggestion {
HighlightSpec::with_fg_bg(
HighlightRole::search_match,
HighlightRole::search_match,
)
} else {
HighlightSpec::with_fg(HighlightRole::autosuggestion)
};
autosuggested_range.len() autosuggested_range.len()
], ],
); );
@ -3047,7 +3058,8 @@ impl<'a> Reader<'a> {
if is_history_search || is_autosuggestion { if is_history_search || is_autosuggestion {
self.input_data.function_set_status(true); self.input_data.function_set_status(true);
if is_autosuggestion && !self.autosuggestion.is_whole_item_from_history { if is_autosuggestion && !self.autosuggestion.is_whole_item_from_history {
self.flash(0..self.command_line.position()); self.flash_autosuggestion = true;
self.flash(0..0);
return; return;
} }
self.history.remove(if is_history_search { self.history.remove(if is_history_search {
@ -4006,6 +4018,7 @@ impl<'a> Reader<'a> {
if self if self
.last_flash .last_flash
.is_some_and(|last_flash| now.duration_since(last_flash) < Duration::from_millis(50)) .is_some_and(|last_flash| now.duration_since(last_flash) < Duration::from_millis(50))
|| flash_range.is_empty() && !self.flash_autosuggestion
{ {
self.last_flash = Some(now); self.last_flash = Some(now);
return; return;
@ -4022,6 +4035,7 @@ impl<'a> Reader<'a> {
self.rendered_layout = data; self.rendered_layout = data;
self.paint_layout(L!("flash"), false); self.paint_layout(L!("flash"), false);
self.flash_autosuggestion = false;
std::thread::sleep(Duration::from_millis(100)); std::thread::sleep(Duration::from_millis(100));
// Re-render with our saved data. // Re-render with our saved data.