Remove HideHover and HoverAt internal actions

This commit is contained in:
Antonio Scandurra 2023-04-28 16:12:24 +02:00
parent e6f561ce46
commit 264a2c1835
4 changed files with 32 additions and 54 deletions

View file

@ -45,7 +45,7 @@ use gpui::{
ModelHandle, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext, ModelHandle, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext,
}; };
use highlight_matching_bracket::refresh_matching_bracket_highlights; 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; pub use items::MAX_TAB_TITLE_LEN;
use itertools::Itertools; use itertools::Itertools;
pub use language::{char_kind, CharKind}; 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() if old_cursor_position.to_display_point(&display_map).row()
!= new_cursor_position.to_display_point(&display_map).row() != new_cursor_position.to_display_point(&display_map).row()
@ -1864,7 +1864,7 @@ impl Editor {
return; return;
} }
if hide_hover(self, &HideHover, cx) { if hide_hover(self, cx) {
return; return;
} }
@ -7014,7 +7014,7 @@ impl View for Editor {
if font_changed { if font_changed {
cx.defer(move |editor, cx: &mut ViewContext<Editor>| { cx.defer(move |editor, cx: &mut ViewContext<Editor>| {
hide_hover(editor, &HideHover, cx); hide_hover(editor, cx);
hide_link_definition(editor, cx); hide_link_definition(editor, cx);
}); });
} }
@ -7063,7 +7063,7 @@ impl View for Editor {
self.buffer self.buffer
.update(cx, |buffer, cx| buffer.remove_active_selections(cx)); .update(cx, |buffer, cx| buffer.remove_active_selections(cx));
self.hide_context_menu(cx); self.hide_context_menu(cx);
hide_hover(self, &HideHover, cx); hide_hover(self, cx);
cx.emit(Event::Blurred); cx.emit(Event::Blurred);
cx.notify(); cx.notify();
} }

View file

@ -7,7 +7,8 @@ use crate::{
display_map::{BlockStyle, DisplaySnapshot, FoldStatus, TransformBlock}, display_map::{BlockStyle, DisplaySnapshot, FoldStatus, TransformBlock},
git::{diff_hunk_to_display, DisplayDiffHunk}, git::{diff_hunk_to_display, DisplayDiffHunk},
hover_popover::{ 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::{ link_go_to_definition::{
GoToFetchedDefinition, GoToFetchedTypeDefinition, UpdateGoToDefinitionLink, GoToFetchedDefinition, GoToFetchedTypeDefinition, UpdateGoToDefinitionLink,
@ -173,15 +174,21 @@ impl EditorElement {
}) })
.on_move({ .on_move({
let position_map = position_map.clone(); let position_map = position_map.clone();
move |event, _editor, cx| { move |event, editor, cx| {
if !Self::mouse_moved(event.platform_event, &position_map, text_bounds, cx) { if !Self::mouse_moved(
editor,
event.platform_event,
&position_map,
text_bounds,
cx,
) {
cx.propagate_event() cx.propagate_event()
} }
} }
}) })
.on_move_out(move |_, _: &mut Editor, cx| { .on_move_out(move |_, editor: &mut Editor, cx| {
if has_popovers { if has_popovers {
cx.dispatch_action(HideHover); hide_hover(editor, cx);
} }
}) })
.on_scroll({ .on_scroll({
@ -388,16 +395,16 @@ impl EditorElement {
}, },
cx, cx,
); );
hover_at(editor, point, cx);
cx.dispatch_action(HoverAt { point });
true true
} else { } else {
cx.dispatch_action(HoverAt { point }); hover_at(editor, point, cx);
false false
} }
} }
fn mouse_moved( fn mouse_moved(
editor: &mut Editor,
MouseMovedEvent { MouseMovedEvent {
modifiers: Modifiers { shift, cmd, .. }, modifiers: Modifiers { shift, cmd, .. },
position, position,
@ -416,8 +423,7 @@ impl EditorElement {
cmd_held: cmd, cmd_held: cmd,
shift_held: shift, shift_held: shift,
}); });
hover_at(editor, point, cx);
cx.dispatch_action(HoverAt { point });
true true
} }

View file

@ -2,7 +2,6 @@ use futures::FutureExt;
use gpui::{ use gpui::{
actions, actions,
elements::{Flex, MouseEventHandler, Padding, Text}, elements::{Flex, MouseEventHandler, Padding, Text},
impl_internal_actions,
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
AnyElement, AppContext, Axis, Element, ModelHandle, Task, ViewContext, 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 MIN_POPOVER_LINE_HEIGHT: f32 = 4.;
pub const HOVER_POPOVER_GAP: f32 = 10.; 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]); actions!(editor, [Hover]);
impl_internal_actions!(editor, [HoverAt, HideHover]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.add_action(hover); 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 /// 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` /// The internal hover action dispatches between `show_hover` or `hide_hover`
/// depending on whether a point to hover over is provided. /// 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 cx.global::<Settings>().hover_popover_enabled {
if let Some(point) = action.point { if let Some(point) = point {
show_hover(editor, point, false, cx); show_hover(editor, point, false, cx);
} else { } 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. /// Hides the type information popup.
/// Triggered by the `Hover` action when the cursor is not over a symbol or when the /// Triggered by the `Hover` action when the cursor is not over a symbol or when the
/// selections changed. /// 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() let did_hide = editor.hover_state.info_popover.take().is_some()
| editor.hover_state.diagnostic_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. // Hover triggered from same location as last time. Don't show again.
return; return;
} else { } else {
hide_hover(editor, &HideHover, cx); hide_hover(editor, cx);
} }
} }
} }
@ -457,15 +445,7 @@ mod tests {
fn test() { printˇln!(); } fn test() { printˇln!(); }
"}); "});
cx.update_editor(|editor, cx| { cx.update_editor(|editor, cx| hover_at(editor, Some(hover_point), cx));
hover_at(
editor,
&HoverAt {
point: Some(hover_point),
},
cx,
)
});
assert!(!cx.editor(|editor, _| editor.hover_state.visible())); assert!(!cx.editor(|editor, _| editor.hover_state.visible()));
// After delay, hover should be visible. // After delay, hover should be visible.
@ -513,15 +493,7 @@ mod tests {
let mut request = cx let mut request = cx
.lsp .lsp
.handle_request::<lsp::request::HoverRequest, _, _>(|_, _| async move { Ok(None) }); .handle_request::<lsp::request::HoverRequest, _, _>(|_, _| async move { Ok(None) });
cx.update_editor(|editor, cx| { cx.update_editor(|editor, cx| hover_at(editor, Some(hover_point), cx));
hover_at(
editor,
&HoverAt {
point: Some(hover_point),
},
cx,
)
});
cx.foreground() cx.foreground()
.advance_clock(Duration::from_millis(HOVER_DELAY_MILLIS + 100)); .advance_clock(Duration::from_millis(HOVER_DELAY_MILLIS + 100));
request.next().await; request.next().await;

View file

@ -17,7 +17,7 @@ use workspace::WorkspaceId;
use crate::{ use crate::{
display_map::{DisplaySnapshot, ToDisplayPoint}, display_map::{DisplaySnapshot, ToDisplayPoint},
hover_popover::{hide_hover, HideHover}, hover_popover::hide_hover,
persistence::DB, persistence::DB,
Anchor, DisplayPoint, Editor, EditorMode, Event, MultiBufferSnapshot, ToPoint, 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)); 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); let workspace_id = self.workspace.as_ref().map(|workspace| workspace.1);
self.scroll_manager self.scroll_manager
.set_scroll_position(scroll_position, &map, local, workspace_id, cx); .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>) { 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 workspace_id = self.workspace.as_ref().map(|workspace| workspace.1);
let top_row = scroll_anchor let top_row = scroll_anchor
.top_anchor .top_anchor
@ -334,7 +334,7 @@ impl Editor {
scroll_anchor: ScrollAnchor, scroll_anchor: ScrollAnchor,
cx: &mut ViewContext<Self>, 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 workspace_id = self.workspace.as_ref().map(|workspace| workspace.1);
let top_row = scroll_anchor let top_row = scroll_anchor
.top_anchor .top_anchor