From 6f7a6e57fcefa7e7c8f78a27dd6e604d73a76e9c Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 18 Jul 2023 02:03:27 +0300 Subject: [PATCH] Avoid excessive blinking on cmd-hover --- crates/terminal/src/terminal.rs | 62 +++++++++++++++++---------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 17bfa1550e..256cbe652d 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -884,36 +884,13 @@ impl Terminal { }; cx.emit(event); } else { - if is_url { - self.update_selected_word( - prev_hovered_word, - maybe_url_or_path, - url_match, - ); - } else { - let (can_open_tx, can_open_rx) = smol::channel::bounded(1); - cx.emit(Event::ProbePathOpen { - maybe_path: maybe_url_or_path.clone(), - can_open_tx, - }); - - cx.spawn(|terminal, mut cx| async move { - let can_open = can_open_rx.recv().await.unwrap_or(false); - terminal.update(&mut cx, |terminal, cx| { - if can_open { - terminal.update_selected_word( - prev_hovered_word, - maybe_url_or_path, - url_match, - ); - } else { - terminal.last_content.last_hovered_word.take(); - } - cx.notify(); - }); - }) - .detach(); - }; + self.update_selected_word( + prev_hovered_word, + maybe_url_or_path, + url_match, + !is_url, + cx, + ); } } } @@ -925,6 +902,8 @@ impl Terminal { prev_word: Option, word: String, word_match: RangeInclusive, + should_probe_word: bool, + cx: &mut ModelContext, ) { if let Some(prev_word) = prev_word { if prev_word.word == word && prev_word.word_match == word_match { @@ -933,6 +912,29 @@ impl Terminal { word_match, id: prev_word.id, }); + } else if should_probe_word { + let (can_open_tx, can_open_rx) = smol::channel::bounded(1); + cx.emit(Event::ProbePathOpen { + maybe_path: word.clone(), + can_open_tx, + }); + + cx.spawn(|terminal, mut cx| async move { + let can_open = can_open_rx.recv().await.unwrap_or(false); + terminal.update(&mut cx, |terminal, cx| { + if can_open { + terminal.last_content.last_hovered_word = Some(HoveredWord { + word, + word_match, + id: terminal.next_link_id(), + }); + } else { + terminal.last_content.last_hovered_word.take(); + } + cx.notify(); + }); + }) + .detach(); } else { self.last_content.last_hovered_word = Some(HoveredWord { word,