Rework terminal highlight event flow
This commit is contained in:
@@ -163,6 +163,7 @@ pub struct TerminalElement {
|
||||
terminal: WeakModelHandle<Terminal>,
|
||||
focused: bool,
|
||||
cursor_visible: bool,
|
||||
can_navigate_to_selected_word: bool,
|
||||
}
|
||||
|
||||
impl TerminalElement {
|
||||
@@ -170,11 +171,13 @@ impl TerminalElement {
|
||||
terminal: WeakModelHandle<Terminal>,
|
||||
focused: bool,
|
||||
cursor_visible: bool,
|
||||
can_navigate_to_selected_word: bool,
|
||||
) -> TerminalElement {
|
||||
TerminalElement {
|
||||
terminal,
|
||||
focused,
|
||||
cursor_visible,
|
||||
can_navigate_to_selected_word,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -580,13 +583,17 @@ impl Element<TerminalView> for TerminalElement {
|
||||
let background_color = terminal_theme.background;
|
||||
let terminal_handle = self.terminal.upgrade(cx).unwrap();
|
||||
|
||||
let last_hovered_hyperlink = terminal_handle.update(cx, |terminal, cx| {
|
||||
let last_hovered_word = terminal_handle.update(cx, |terminal, cx| {
|
||||
terminal.set_size(dimensions);
|
||||
terminal.try_sync(cx);
|
||||
terminal.last_content.last_hovered_word.clone()
|
||||
if self.can_navigate_to_selected_word && terminal.can_navigate_to_selected_word() {
|
||||
terminal.last_content.last_hovered_word.clone()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
|
||||
let hyperlink_tooltip = last_hovered_hyperlink.map(|hovered_word| {
|
||||
let hyperlink_tooltip = last_hovered_word.clone().map(|hovered_word| {
|
||||
let mut tooltip = Overlay::new(
|
||||
Empty::new()
|
||||
.contained()
|
||||
@@ -619,7 +626,6 @@ impl Element<TerminalView> for TerminalElement {
|
||||
cursor_char,
|
||||
selection,
|
||||
cursor,
|
||||
last_hovered_word,
|
||||
..
|
||||
} = { &terminal_handle.read(cx).last_content };
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ use terminal::{
|
||||
index::Point,
|
||||
term::{search::RegexSearch, TermMode},
|
||||
},
|
||||
Event, Terminal, TerminalBlink, WorkingDirectory,
|
||||
Event, MaybeNavigationTarget, Terminal, TerminalBlink, WorkingDirectory,
|
||||
};
|
||||
use util::{paths::PathLikeWithPosition, ResultExt};
|
||||
use workspace::{
|
||||
@@ -93,6 +93,7 @@ pub struct TerminalView {
|
||||
blinking_on: bool,
|
||||
blinking_paused: bool,
|
||||
blink_epoch: usize,
|
||||
can_navigate_to_selected_word: bool,
|
||||
workspace_id: WorkspaceId,
|
||||
}
|
||||
|
||||
@@ -169,55 +170,61 @@ impl TerminalView {
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
Event::ProbePathOpen {
|
||||
maybe_path,
|
||||
can_open_tx,
|
||||
} => {
|
||||
let can_open = !possible_open_targets(&workspace, maybe_path, cx).is_empty();
|
||||
can_open_tx.send_blocking(can_open).ok();
|
||||
}
|
||||
Event::OpenUrl(url) => cx.platform().open_url(url),
|
||||
Event::OpenPath(maybe_path) => {
|
||||
let potential_abs_paths = possible_open_targets(&workspace, maybe_path, cx);
|
||||
if let Some(path) = potential_abs_paths.into_iter().next() {
|
||||
let visible = path.path_like.is_dir();
|
||||
let task_workspace = workspace.clone();
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
let opened_item = task_workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
workspace.open_abs_path(path.path_like, visible, cx)
|
||||
})
|
||||
.context("workspace update")?
|
||||
.await
|
||||
.context("workspace update")?;
|
||||
if let Some(row) = path.row {
|
||||
let col = path.column.unwrap_or(0);
|
||||
if let Some(active_editor) = opened_item.downcast::<Editor>() {
|
||||
active_editor
|
||||
.downgrade()
|
||||
.update(&mut cx, |editor, cx| {
|
||||
let snapshot = editor.snapshot(cx).display_snapshot;
|
||||
let point = snapshot.buffer_snapshot.clip_point(
|
||||
language::Point::new(
|
||||
row.saturating_sub(1),
|
||||
col.saturating_sub(1),
|
||||
),
|
||||
Bias::Left,
|
||||
);
|
||||
editor.change_selections(
|
||||
Some(Autoscroll::center()),
|
||||
cx,
|
||||
|s| s.select_ranges([point..point]),
|
||||
);
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
}
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
Event::NewNavigationTarget(maybe_navigation_target) => {
|
||||
this.can_navigate_to_selected_word = match maybe_navigation_target {
|
||||
MaybeNavigationTarget::Url(_) => true,
|
||||
MaybeNavigationTarget::PathLike(maybe_path) => {
|
||||
!possible_open_targets(&workspace, maybe_path, cx).is_empty()
|
||||
}
|
||||
}
|
||||
}
|
||||
Event::Open(maybe_navigation_target) => match maybe_navigation_target {
|
||||
MaybeNavigationTarget::Url(url) => cx.platform().open_url(url),
|
||||
MaybeNavigationTarget::PathLike(maybe_path) => {
|
||||
if !this.can_navigate_to_selected_word {
|
||||
return;
|
||||
}
|
||||
let potential_abs_paths = possible_open_targets(&workspace, maybe_path, cx);
|
||||
if let Some(path) = potential_abs_paths.into_iter().next() {
|
||||
let visible = path.path_like.is_dir();
|
||||
let task_workspace = workspace.clone();
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
let opened_item = task_workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
workspace.open_abs_path(path.path_like, visible, cx)
|
||||
})
|
||||
.context("workspace update")?
|
||||
.await
|
||||
.context("workspace update")?;
|
||||
if let Some(row) = path.row {
|
||||
let col = path.column.unwrap_or(0);
|
||||
if let Some(active_editor) = opened_item.downcast::<Editor>() {
|
||||
active_editor
|
||||
.downgrade()
|
||||
.update(&mut cx, |editor, cx| {
|
||||
let snapshot = editor.snapshot(cx).display_snapshot;
|
||||
let point = snapshot.buffer_snapshot.clip_point(
|
||||
language::Point::new(
|
||||
row.saturating_sub(1),
|
||||
col.saturating_sub(1),
|
||||
),
|
||||
Bias::Left,
|
||||
);
|
||||
editor.change_selections(
|
||||
Some(Autoscroll::center()),
|
||||
cx,
|
||||
|s| s.select_ranges([point..point]),
|
||||
);
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
}
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => cx.emit(event.clone()),
|
||||
})
|
||||
.detach();
|
||||
@@ -231,6 +238,7 @@ impl TerminalView {
|
||||
blinking_on: false,
|
||||
blinking_paused: false,
|
||||
blink_epoch: 0,
|
||||
can_navigate_to_selected_word: false,
|
||||
workspace_id,
|
||||
}
|
||||
}
|
||||
@@ -466,6 +474,7 @@ impl View for TerminalView {
|
||||
terminal_handle,
|
||||
focused,
|
||||
self.should_show_cursor(focused, cx),
|
||||
self.can_navigate_to_selected_word,
|
||||
)
|
||||
.contained(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user