mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 18:46:49 +00:00
Remove HideHover
and HoverAt
internal actions
This commit is contained in:
parent
e6f561ce46
commit
264a2c1835
4 changed files with 32 additions and 54 deletions
|
@ -45,7 +45,7 @@ use gpui::{
|
|||
ModelHandle, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext,
|
||||
};
|
||||
use highlight_matching_bracket::refresh_matching_bracket_highlights;
|
||||
use hover_popover::{hide_hover, HideHover, HoverState};
|
||||
use hover_popover::{hide_hover, HoverState};
|
||||
pub use items::MAX_TAB_TITLE_LEN;
|
||||
use itertools::Itertools;
|
||||
pub use language::{char_kind, CharKind};
|
||||
|
@ -1480,7 +1480,7 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
|
||||
hide_hover(self, &HideHover, cx);
|
||||
hide_hover(self, cx);
|
||||
|
||||
if old_cursor_position.to_display_point(&display_map).row()
|
||||
!= new_cursor_position.to_display_point(&display_map).row()
|
||||
|
@ -1864,7 +1864,7 @@ impl Editor {
|
|||
return;
|
||||
}
|
||||
|
||||
if hide_hover(self, &HideHover, cx) {
|
||||
if hide_hover(self, cx) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -7014,7 +7014,7 @@ impl View for Editor {
|
|||
|
||||
if font_changed {
|
||||
cx.defer(move |editor, cx: &mut ViewContext<Editor>| {
|
||||
hide_hover(editor, &HideHover, cx);
|
||||
hide_hover(editor, cx);
|
||||
hide_link_definition(editor, cx);
|
||||
});
|
||||
}
|
||||
|
@ -7063,7 +7063,7 @@ impl View for Editor {
|
|||
self.buffer
|
||||
.update(cx, |buffer, cx| buffer.remove_active_selections(cx));
|
||||
self.hide_context_menu(cx);
|
||||
hide_hover(self, &HideHover, cx);
|
||||
hide_hover(self, cx);
|
||||
cx.emit(Event::Blurred);
|
||||
cx.notify();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ use crate::{
|
|||
display_map::{BlockStyle, DisplaySnapshot, FoldStatus, TransformBlock},
|
||||
git::{diff_hunk_to_display, DisplayDiffHunk},
|
||||
hover_popover::{
|
||||
HideHover, HoverAt, HOVER_POPOVER_GAP, MIN_POPOVER_CHARACTER_WIDTH, MIN_POPOVER_LINE_HEIGHT,
|
||||
hide_hover, hover_at, HOVER_POPOVER_GAP, MIN_POPOVER_CHARACTER_WIDTH,
|
||||
MIN_POPOVER_LINE_HEIGHT,
|
||||
},
|
||||
link_go_to_definition::{
|
||||
GoToFetchedDefinition, GoToFetchedTypeDefinition, UpdateGoToDefinitionLink,
|
||||
|
@ -173,15 +174,21 @@ impl EditorElement {
|
|||
})
|
||||
.on_move({
|
||||
let position_map = position_map.clone();
|
||||
move |event, _editor, cx| {
|
||||
if !Self::mouse_moved(event.platform_event, &position_map, text_bounds, cx) {
|
||||
move |event, editor, cx| {
|
||||
if !Self::mouse_moved(
|
||||
editor,
|
||||
event.platform_event,
|
||||
&position_map,
|
||||
text_bounds,
|
||||
cx,
|
||||
) {
|
||||
cx.propagate_event()
|
||||
}
|
||||
}
|
||||
})
|
||||
.on_move_out(move |_, _: &mut Editor, cx| {
|
||||
.on_move_out(move |_, editor: &mut Editor, cx| {
|
||||
if has_popovers {
|
||||
cx.dispatch_action(HideHover);
|
||||
hide_hover(editor, cx);
|
||||
}
|
||||
})
|
||||
.on_scroll({
|
||||
|
@ -388,16 +395,16 @@ impl EditorElement {
|
|||
},
|
||||
cx,
|
||||
);
|
||||
|
||||
cx.dispatch_action(HoverAt { point });
|
||||
hover_at(editor, point, cx);
|
||||
true
|
||||
} else {
|
||||
cx.dispatch_action(HoverAt { point });
|
||||
hover_at(editor, point, cx);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn mouse_moved(
|
||||
editor: &mut Editor,
|
||||
MouseMovedEvent {
|
||||
modifiers: Modifiers { shift, cmd, .. },
|
||||
position,
|
||||
|
@ -416,8 +423,7 @@ impl EditorElement {
|
|||
cmd_held: cmd,
|
||||
shift_held: shift,
|
||||
});
|
||||
|
||||
cx.dispatch_action(HoverAt { point });
|
||||
hover_at(editor, point, cx);
|
||||
|
||||
true
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ use futures::FutureExt;
|
|||
use gpui::{
|
||||
actions,
|
||||
elements::{Flex, MouseEventHandler, Padding, Text},
|
||||
impl_internal_actions,
|
||||
platform::{CursorStyle, MouseButton},
|
||||
AnyElement, AppContext, Axis, Element, ModelHandle, Task, ViewContext,
|
||||
};
|
||||
|
@ -24,21 +23,10 @@ pub const MIN_POPOVER_CHARACTER_WIDTH: f32 = 20.;
|
|||
pub const MIN_POPOVER_LINE_HEIGHT: f32 = 4.;
|
||||
pub const HOVER_POPOVER_GAP: f32 = 10.;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct HoverAt {
|
||||
pub point: Option<DisplayPoint>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub struct HideHover;
|
||||
|
||||
actions!(editor, [Hover]);
|
||||
impl_internal_actions!(editor, [HoverAt, HideHover]);
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.add_action(hover);
|
||||
cx.add_action(hover_at);
|
||||
cx.add_action(hide_hover);
|
||||
}
|
||||
|
||||
/// Bindable action which uses the most recent selection head to trigger a hover
|
||||
|
@ -49,12 +37,12 @@ pub fn hover(editor: &mut Editor, _: &Hover, cx: &mut ViewContext<Editor>) {
|
|||
|
||||
/// The internal hover action dispatches between `show_hover` or `hide_hover`
|
||||
/// depending on whether a point to hover over is provided.
|
||||
pub fn hover_at(editor: &mut Editor, action: &HoverAt, cx: &mut ViewContext<Editor>) {
|
||||
pub fn hover_at(editor: &mut Editor, point: Option<DisplayPoint>, cx: &mut ViewContext<Editor>) {
|
||||
if cx.global::<Settings>().hover_popover_enabled {
|
||||
if let Some(point) = action.point {
|
||||
if let Some(point) = point {
|
||||
show_hover(editor, point, false, cx);
|
||||
} else {
|
||||
hide_hover(editor, &HideHover, cx);
|
||||
hide_hover(editor, cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +50,7 @@ pub fn hover_at(editor: &mut Editor, action: &HoverAt, cx: &mut ViewContext<Edit
|
|||
/// Hides the type information popup.
|
||||
/// Triggered by the `Hover` action when the cursor is not over a symbol or when the
|
||||
/// selections changed.
|
||||
pub fn hide_hover(editor: &mut Editor, _: &HideHover, cx: &mut ViewContext<Editor>) -> bool {
|
||||
pub fn hide_hover(editor: &mut Editor, cx: &mut ViewContext<Editor>) -> bool {
|
||||
let did_hide = editor.hover_state.info_popover.take().is_some()
|
||||
| editor.hover_state.diagnostic_popover.take().is_some();
|
||||
|
||||
|
@ -129,7 +117,7 @@ fn show_hover(
|
|||
// Hover triggered from same location as last time. Don't show again.
|
||||
return;
|
||||
} else {
|
||||
hide_hover(editor, &HideHover, cx);
|
||||
hide_hover(editor, cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -457,15 +445,7 @@ mod tests {
|
|||
fn test() { printˇln!(); }
|
||||
"});
|
||||
|
||||
cx.update_editor(|editor, cx| {
|
||||
hover_at(
|
||||
editor,
|
||||
&HoverAt {
|
||||
point: Some(hover_point),
|
||||
},
|
||||
cx,
|
||||
)
|
||||
});
|
||||
cx.update_editor(|editor, cx| hover_at(editor, Some(hover_point), cx));
|
||||
assert!(!cx.editor(|editor, _| editor.hover_state.visible()));
|
||||
|
||||
// After delay, hover should be visible.
|
||||
|
@ -513,15 +493,7 @@ mod tests {
|
|||
let mut request = cx
|
||||
.lsp
|
||||
.handle_request::<lsp::request::HoverRequest, _, _>(|_, _| async move { Ok(None) });
|
||||
cx.update_editor(|editor, cx| {
|
||||
hover_at(
|
||||
editor,
|
||||
&HoverAt {
|
||||
point: Some(hover_point),
|
||||
},
|
||||
cx,
|
||||
)
|
||||
});
|
||||
cx.update_editor(|editor, cx| hover_at(editor, Some(hover_point), cx));
|
||||
cx.foreground()
|
||||
.advance_clock(Duration::from_millis(HOVER_DELAY_MILLIS + 100));
|
||||
request.next().await;
|
||||
|
|
|
@ -17,7 +17,7 @@ use workspace::WorkspaceId;
|
|||
|
||||
use crate::{
|
||||
display_map::{DisplaySnapshot, ToDisplayPoint},
|
||||
hover_popover::{hide_hover, HideHover},
|
||||
hover_popover::hide_hover,
|
||||
persistence::DB,
|
||||
Anchor, DisplayPoint, Editor, EditorMode, Event, MultiBufferSnapshot, ToPoint,
|
||||
};
|
||||
|
@ -307,7 +307,7 @@ impl Editor {
|
|||
) {
|
||||
let map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
|
||||
hide_hover(self, &HideHover, cx);
|
||||
hide_hover(self, cx);
|
||||
let workspace_id = self.workspace.as_ref().map(|workspace| workspace.1);
|
||||
self.scroll_manager
|
||||
.set_scroll_position(scroll_position, &map, local, workspace_id, cx);
|
||||
|
@ -319,7 +319,7 @@ impl Editor {
|
|||
}
|
||||
|
||||
pub fn set_scroll_anchor(&mut self, scroll_anchor: ScrollAnchor, cx: &mut ViewContext<Self>) {
|
||||
hide_hover(self, &HideHover, cx);
|
||||
hide_hover(self, cx);
|
||||
let workspace_id = self.workspace.as_ref().map(|workspace| workspace.1);
|
||||
let top_row = scroll_anchor
|
||||
.top_anchor
|
||||
|
@ -334,7 +334,7 @@ impl Editor {
|
|||
scroll_anchor: ScrollAnchor,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
hide_hover(self, &HideHover, cx);
|
||||
hide_hover(self, cx);
|
||||
let workspace_id = self.workspace.as_ref().map(|workspace| workspace.1);
|
||||
let top_row = scroll_anchor
|
||||
.top_anchor
|
||||
|
|
Loading…
Reference in a new issue