mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 08:54:04 +00:00
Merge pull request #1519 from zed-industries/go-to-def-link-font-size-change
Clear any stale go-to-definition link when resizing the buffer font
This commit is contained in:
commit
1f00f6c163
4 changed files with 57 additions and 14 deletions
|
@ -42,7 +42,7 @@ use language::{
|
||||||
DiagnosticSeverity, IndentKind, IndentSize, Language, OffsetRangeExt, OffsetUtf16, Point,
|
DiagnosticSeverity, IndentKind, IndentSize, Language, OffsetRangeExt, OffsetUtf16, Point,
|
||||||
Selection, SelectionGoal, TransactionId,
|
Selection, SelectionGoal, TransactionId,
|
||||||
};
|
};
|
||||||
use link_go_to_definition::LinkGoToDefinitionState;
|
use link_go_to_definition::{hide_link_definition, LinkGoToDefinitionState};
|
||||||
pub use multi_buffer::{
|
pub use multi_buffer::{
|
||||||
Anchor, AnchorRangeExt, ExcerptId, ExcerptRange, MultiBuffer, MultiBufferSnapshot, ToOffset,
|
Anchor, AnchorRangeExt, ExcerptId, ExcerptRange, MultiBuffer, MultiBufferSnapshot, ToOffset,
|
||||||
ToPoint,
|
ToPoint,
|
||||||
|
@ -6010,6 +6010,7 @@ impl View for Editor {
|
||||||
if let Some(editor) = handle.upgrade(cx) {
|
if let Some(editor) = handle.upgrade(cx) {
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
hide_hover(editor, cx);
|
hide_hover(editor, cx);
|
||||||
|
hide_link_definition(editor, cx);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
Anchor, Autoscroll, Editor, Event, ExcerptId, MultiBuffer, NavigationData, ToPoint as _,
|
link_go_to_definition::hide_link_definition, Anchor, Autoscroll, Editor, Event, ExcerptId,
|
||||||
|
MultiBuffer, NavigationData, ToPoint as _,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
|
@ -376,6 +377,11 @@ impl Item for Editor {
|
||||||
self.push_to_nav_history(selection.head(), None, cx);
|
self.push_to_nav_history(selection.head(), None, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn workspace_deactivated(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
hide_link_definition(self, cx);
|
||||||
|
self.link_go_to_definition_state.last_mouse_location = None;
|
||||||
|
}
|
||||||
|
|
||||||
fn is_dirty(&self, cx: &AppContext) -> bool {
|
fn is_dirty(&self, cx: &AppContext) -> bool {
|
||||||
self.buffer().read(cx).read(cx).is_dirty()
|
self.buffer().read(cx).read(cx).is_dirty()
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
cx.add_action(go_to_fetched_type_definition);
|
cx.add_action(go_to_fetched_type_definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct LinkGoToDefinitionState {
|
pub struct LinkGoToDefinitionState {
|
||||||
pub last_mouse_location: Option<Anchor>,
|
pub last_mouse_location: Option<Anchor>,
|
||||||
pub symbol_range: Option<Range<Anchor>>,
|
pub symbol_range: Option<Range<Anchor>>,
|
||||||
|
@ -706,7 +706,34 @@ mod tests {
|
||||||
fn do_work() { «test»(); }
|
fn do_work() { «test»(); }
|
||||||
"});
|
"});
|
||||||
|
|
||||||
// Moving within symbol range doesn't re-request
|
// Deactivating the window dismisses the highlight
|
||||||
|
cx.update_workspace(|workspace, cx| {
|
||||||
|
workspace.on_window_activation_changed(false, cx);
|
||||||
|
});
|
||||||
|
cx.assert_editor_text_highlights::<LinkGoToDefinitionState>(indoc! {"
|
||||||
|
fn test() { do_work(); }
|
||||||
|
fn do_work() { test(); }
|
||||||
|
"});
|
||||||
|
|
||||||
|
// Moving the mouse restores the highlights.
|
||||||
|
cx.update_editor(|editor, cx| {
|
||||||
|
update_go_to_definition_link(
|
||||||
|
editor,
|
||||||
|
&UpdateGoToDefinitionLink {
|
||||||
|
point: Some(hover_point),
|
||||||
|
cmd_held: true,
|
||||||
|
shift_held: false,
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
cx.foreground().run_until_parked();
|
||||||
|
cx.assert_editor_text_highlights::<LinkGoToDefinitionState>(indoc! {"
|
||||||
|
fn test() { do_work(); }
|
||||||
|
fn do_work() { «test»(); }
|
||||||
|
"});
|
||||||
|
|
||||||
|
// Moving again within the same symbol range doesn't re-request
|
||||||
let hover_point = cx.display_point(indoc! {"
|
let hover_point = cx.display_point(indoc! {"
|
||||||
fn test() { do_work(); }
|
fn test() { do_work(); }
|
||||||
fn do_work() { tesˇt(); }
|
fn do_work() { tesˇt(); }
|
||||||
|
|
|
@ -261,6 +261,7 @@ pub struct AppState {
|
||||||
|
|
||||||
pub trait Item: View {
|
pub trait Item: View {
|
||||||
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
||||||
|
fn workspace_deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
||||||
fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
|
fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -433,6 +434,7 @@ pub trait ItemHandle: 'static + fmt::Debug {
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
);
|
);
|
||||||
fn deactivated(&self, cx: &mut MutableAppContext);
|
fn deactivated(&self, cx: &mut MutableAppContext);
|
||||||
|
fn workspace_deactivated(&self, cx: &mut MutableAppContext);
|
||||||
fn navigate(&self, data: Box<dyn Any>, cx: &mut MutableAppContext) -> bool;
|
fn navigate(&self, data: Box<dyn Any>, cx: &mut MutableAppContext) -> bool;
|
||||||
fn id(&self) -> usize;
|
fn id(&self) -> usize;
|
||||||
fn to_any(&self) -> AnyViewHandle;
|
fn to_any(&self) -> AnyViewHandle;
|
||||||
|
@ -629,6 +631,10 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
||||||
self.update(cx, |this, cx| this.deactivated(cx));
|
self.update(cx, |this, cx| this.deactivated(cx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn workspace_deactivated(&self, cx: &mut MutableAppContext) {
|
||||||
|
self.update(cx, |this, cx| this.workspace_deactivated(cx));
|
||||||
|
}
|
||||||
|
|
||||||
fn navigate(&self, data: Box<dyn Any>, cx: &mut MutableAppContext) -> bool {
|
fn navigate(&self, data: Box<dyn Any>, cx: &mut MutableAppContext) -> bool {
|
||||||
self.update(cx, |this, cx| this.navigate(data, cx))
|
self.update(cx, |this, cx| this.navigate(data, cx))
|
||||||
}
|
}
|
||||||
|
@ -2383,19 +2389,22 @@ impl Workspace {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_window_activation_changed(&mut self, active: bool, cx: &mut ViewContext<Self>) {
|
pub fn on_window_activation_changed(&mut self, active: bool, cx: &mut ViewContext<Self>) {
|
||||||
if !active
|
if !active {
|
||||||
&& matches!(
|
|
||||||
cx.global::<Settings>().autosave,
|
|
||||||
Autosave::OnWindowChange | Autosave::OnFocusChange
|
|
||||||
)
|
|
||||||
{
|
|
||||||
for pane in &self.panes {
|
for pane in &self.panes {
|
||||||
pane.update(cx, |pane, cx| {
|
pane.update(cx, |pane, cx| {
|
||||||
|
if let Some(item) = pane.active_item() {
|
||||||
|
item.workspace_deactivated(cx);
|
||||||
|
}
|
||||||
|
if matches!(
|
||||||
|
cx.global::<Settings>().autosave,
|
||||||
|
Autosave::OnWindowChange | Autosave::OnFocusChange
|
||||||
|
) {
|
||||||
for item in pane.items() {
|
for item in pane.items() {
|
||||||
Pane::autosave_item(item.as_ref(), self.project.clone(), cx)
|
Pane::autosave_item(item.as_ref(), self.project.clone(), cx)
|
||||||
.detach_and_log_err(cx);
|
.detach_and_log_err(cx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue