uncomment mouse moved
This commit is contained in:
parent
e4bc03217d
commit
cd3773531c
2 changed files with 225 additions and 212 deletions
|
@ -2,6 +2,10 @@ use crate::{
|
||||||
display_map::{BlockStyle, DisplaySnapshot, FoldStatus, HighlightedChunk, ToDisplayPoint},
|
display_map::{BlockStyle, DisplaySnapshot, FoldStatus, HighlightedChunk, ToDisplayPoint},
|
||||||
editor_settings::ShowScrollbar,
|
editor_settings::ShowScrollbar,
|
||||||
git::{diff_hunk_to_display, DisplayDiffHunk},
|
git::{diff_hunk_to_display, DisplayDiffHunk},
|
||||||
|
hover_popover::hover_at,
|
||||||
|
link_go_to_definition::{
|
||||||
|
update_go_to_definition_link, update_inlay_link_and_hover_points, GoToDefinitionTrigger,
|
||||||
|
},
|
||||||
scroll::scroll_amount::ScrollAmount,
|
scroll::scroll_amount::ScrollAmount,
|
||||||
CursorShape, DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle,
|
CursorShape, DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle,
|
||||||
HalfPageDown, HalfPageUp, LineDown, LineUp, MoveDown, PageDown, PageUp, Point, Selection,
|
HalfPageDown, HalfPageUp, LineDown, LineUp, MoveDown, PageDown, PageUp, Point, Selection,
|
||||||
|
@ -12,9 +16,9 @@ use collections::{BTreeMap, HashMap};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
black, hsla, point, px, relative, size, transparent_black, Action, AnyElement,
|
black, hsla, point, px, relative, size, transparent_black, Action, AnyElement,
|
||||||
BorrowAppContext, BorrowWindow, Bounds, ContentMask, Corners, DispatchContext, DispatchPhase,
|
BorrowAppContext, BorrowWindow, Bounds, ContentMask, Corners, DispatchContext, DispatchPhase,
|
||||||
Edges, Element, ElementId, Entity, Hsla, KeyDownEvent, KeyListener, KeyMatch, Line, Pixels,
|
Edges, Element, ElementId, Entity, Hsla, KeyDownEvent, KeyListener, KeyMatch, Line, Modifiers,
|
||||||
ScrollWheelEvent, ShapedGlyph, Size, StatefulInteraction, Style, TextRun, TextStyle,
|
MouseMoveEvent, Pixels, ScrollWheelEvent, ShapedGlyph, Size, StatefulInteraction, Style,
|
||||||
TextSystem, ViewContext, WindowContext,
|
TextRun, TextStyle, TextSystem, ViewContext, WindowContext,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use language::language_settings::ShowWhitespaceSetting;
|
use language::language_settings::ShowWhitespaceSetting;
|
||||||
|
@ -423,50 +427,50 @@ impl EditorElement {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// fn mouse_moved(
|
fn mouse_moved(
|
||||||
// editor: &mut Editor,
|
editor: &mut Editor,
|
||||||
// MouseMovedEvent {
|
MouseMoveEvent {
|
||||||
// modifiers: Modifiers { shift, cmd, .. },
|
modifiers: Modifiers { shift, command, .. },
|
||||||
// position,
|
position,
|
||||||
// ..
|
..
|
||||||
// }: MouseMovedEvent,
|
}: &MouseMoveEvent,
|
||||||
// position_map: &PositionMap,
|
position_map: &PositionMap,
|
||||||
// text_bounds: Bounds<Pixels>,
|
text_bounds: Bounds<Pixels>,
|
||||||
// cx: &mut ViewContext<Editor>,
|
cx: &mut ViewContext<Editor>,
|
||||||
// ) -> bool {
|
) -> bool {
|
||||||
// // This will be handled more correctly once https://github.com/zed-industries/zed/issues/1218 is completed
|
// This will be handled more correctly once https://github.com/zed-industries/zed/issues/1218 is completed
|
||||||
// // Don't trigger hover popover if mouse is hovering over context menu
|
// Don't trigger hover popover if mouse is hovering over context menu
|
||||||
// if text_bounds.contains_point(position) {
|
if text_bounds.contains_point(position) {
|
||||||
// let point_for_position = position_map.point_for_position(text_bounds, position);
|
let point_for_position = position_map.point_for_position(text_bounds, position.clone());
|
||||||
// match point_for_position.as_valid() {
|
match point_for_position.as_valid() {
|
||||||
// Some(point) => {
|
Some(point) => {
|
||||||
// update_go_to_definition_link(
|
update_go_to_definition_link(
|
||||||
// editor,
|
editor,
|
||||||
// Some(GoToDefinitionTrigger::Text(point)),
|
Some(GoToDefinitionTrigger::Text(point)),
|
||||||
// cmd,
|
*command,
|
||||||
// shift,
|
*shift,
|
||||||
// cx,
|
cx,
|
||||||
// );
|
);
|
||||||
// hover_at(editor, Some(point), cx);
|
hover_at(editor, Some(point), cx);
|
||||||
// }
|
}
|
||||||
// None => {
|
None => {
|
||||||
// update_inlay_link_and_hover_points(
|
update_inlay_link_and_hover_points(
|
||||||
// &position_map.snapshot,
|
&position_map.snapshot,
|
||||||
// point_for_position,
|
point_for_position,
|
||||||
// editor,
|
editor,
|
||||||
// cmd,
|
*command,
|
||||||
// shift,
|
*shift,
|
||||||
// cx,
|
cx,
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// update_go_to_definition_link(editor, None, cmd, shift, cx);
|
update_go_to_definition_link(editor, None, *command, *shift, cx);
|
||||||
// hover_at(editor, None, cx);
|
hover_at(editor, None, cx);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// true
|
true
|
||||||
// }
|
}
|
||||||
|
|
||||||
fn scroll(
|
fn scroll(
|
||||||
editor: &mut Editor,
|
editor: &mut Editor,
|
||||||
|
@ -2772,6 +2776,18 @@ impl Element<Editor> for EditorElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
cx.on_mouse_event({
|
||||||
|
let position_map = layout.position_map.clone();
|
||||||
|
move |editor, event: &MouseMoveEvent, phase, cx| {
|
||||||
|
if phase != DispatchPhase::Bubble {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if Self::mouse_moved(editor, event, &position_map, bounds, cx) {
|
||||||
|
cx.stop_propagation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if editor.focus_handle.is_focused(cx) {
|
if editor.focus_handle.is_focused(cx) {
|
||||||
cx.handle_text_input();
|
cx.handle_text_input();
|
||||||
|
|
|
@ -171,173 +171,170 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
shift_held: bool,
|
shift_held: bool,
|
||||||
cx: &mut ViewContext<'_, Editor>,
|
cx: &mut ViewContext<'_, Editor>,
|
||||||
) {
|
) {
|
||||||
todo!("old implementation below")
|
let hovered_offset = if point_for_position.column_overshoot_after_line_end == 0 {
|
||||||
}
|
Some(snapshot.display_point_to_inlay_offset(point_for_position.exact_unclipped, Bias::Left))
|
||||||
// ) {
|
} else {
|
||||||
// let hovered_offset = if point_for_position.column_overshoot_after_line_end == 0 {
|
None
|
||||||
// Some(snapshot.display_point_to_inlay_offset(point_for_position.exact_unclipped, Bias::Left))
|
};
|
||||||
// } else {
|
let mut go_to_definition_updated = false;
|
||||||
// None
|
let mut hover_updated = false;
|
||||||
// };
|
if let Some(hovered_offset) = hovered_offset {
|
||||||
// let mut go_to_definition_updated = false;
|
let buffer_snapshot = editor.buffer().read(cx).snapshot(cx);
|
||||||
// let mut hover_updated = false;
|
let previous_valid_anchor = buffer_snapshot.anchor_at(
|
||||||
// if let Some(hovered_offset) = hovered_offset {
|
point_for_position.previous_valid.to_point(snapshot),
|
||||||
// let buffer_snapshot = editor.buffer().read(cx).snapshot(cx);
|
Bias::Left,
|
||||||
// let previous_valid_anchor = buffer_snapshot.anchor_at(
|
);
|
||||||
// point_for_position.previous_valid.to_point(snapshot),
|
let next_valid_anchor = buffer_snapshot.anchor_at(
|
||||||
// Bias::Left,
|
point_for_position.next_valid.to_point(snapshot),
|
||||||
// );
|
Bias::Right,
|
||||||
// let next_valid_anchor = buffer_snapshot.anchor_at(
|
);
|
||||||
// point_for_position.next_valid.to_point(snapshot),
|
if let Some(hovered_hint) = editor
|
||||||
// Bias::Right,
|
.visible_inlay_hints(cx)
|
||||||
// );
|
.into_iter()
|
||||||
// if let Some(hovered_hint) = editor
|
.skip_while(|hint| {
|
||||||
// .visible_inlay_hints(cx)
|
hint.position
|
||||||
// .into_iter()
|
.cmp(&previous_valid_anchor, &buffer_snapshot)
|
||||||
// .skip_while(|hint| {
|
.is_lt()
|
||||||
// hint.position
|
})
|
||||||
// .cmp(&previous_valid_anchor, &buffer_snapshot)
|
.take_while(|hint| {
|
||||||
// .is_lt()
|
hint.position
|
||||||
// })
|
.cmp(&next_valid_anchor, &buffer_snapshot)
|
||||||
// .take_while(|hint| {
|
.is_le()
|
||||||
// hint.position
|
})
|
||||||
// .cmp(&next_valid_anchor, &buffer_snapshot)
|
.max_by_key(|hint| hint.id)
|
||||||
// .is_le()
|
{
|
||||||
// })
|
let inlay_hint_cache = editor.inlay_hint_cache();
|
||||||
// .max_by_key(|hint| hint.id)
|
let excerpt_id = previous_valid_anchor.excerpt_id;
|
||||||
// {
|
if let Some(cached_hint) = inlay_hint_cache.hint_by_id(excerpt_id, hovered_hint.id) {
|
||||||
// let inlay_hint_cache = editor.inlay_hint_cache();
|
match cached_hint.resolve_state {
|
||||||
// let excerpt_id = previous_valid_anchor.excerpt_id;
|
ResolveState::CanResolve(_, _) => {
|
||||||
// if let Some(cached_hint) = inlay_hint_cache.hint_by_id(excerpt_id, hovered_hint.id) {
|
if let Some(buffer_id) = previous_valid_anchor.buffer_id {
|
||||||
// match cached_hint.resolve_state {
|
inlay_hint_cache.spawn_hint_resolve(
|
||||||
// ResolveState::CanResolve(_, _) => {
|
buffer_id,
|
||||||
// if let Some(buffer_id) = previous_valid_anchor.buffer_id {
|
excerpt_id,
|
||||||
// inlay_hint_cache.spawn_hint_resolve(
|
hovered_hint.id,
|
||||||
// buffer_id,
|
cx,
|
||||||
// excerpt_id,
|
);
|
||||||
// hovered_hint.id,
|
}
|
||||||
// cx,
|
}
|
||||||
// );
|
ResolveState::Resolved => {
|
||||||
// }
|
let mut extra_shift_left = 0;
|
||||||
// }
|
let mut extra_shift_right = 0;
|
||||||
// ResolveState::Resolved => {
|
if cached_hint.padding_left {
|
||||||
// let mut extra_shift_left = 0;
|
extra_shift_left += 1;
|
||||||
// let mut extra_shift_right = 0;
|
extra_shift_right += 1;
|
||||||
// if cached_hint.padding_left {
|
}
|
||||||
// extra_shift_left += 1;
|
if cached_hint.padding_right {
|
||||||
// extra_shift_right += 1;
|
extra_shift_right += 1;
|
||||||
// }
|
}
|
||||||
// if cached_hint.padding_right {
|
match cached_hint.label {
|
||||||
// extra_shift_right += 1;
|
project::InlayHintLabel::String(_) => {
|
||||||
// }
|
if let Some(tooltip) = cached_hint.tooltip {
|
||||||
// match cached_hint.label {
|
hover_popover::hover_at_inlay(
|
||||||
// project::InlayHintLabel::String(_) => {
|
editor,
|
||||||
// if let Some(tooltip) = cached_hint.tooltip {
|
InlayHover {
|
||||||
// hover_popover::hover_at_inlay(
|
excerpt: excerpt_id,
|
||||||
// editor,
|
tooltip: match tooltip {
|
||||||
// InlayHover {
|
InlayHintTooltip::String(text) => HoverBlock {
|
||||||
// excerpt: excerpt_id,
|
text,
|
||||||
// tooltip: match tooltip {
|
kind: HoverBlockKind::PlainText,
|
||||||
// InlayHintTooltip::String(text) => HoverBlock {
|
},
|
||||||
// text,
|
InlayHintTooltip::MarkupContent(content) => {
|
||||||
// kind: HoverBlockKind::PlainText,
|
HoverBlock {
|
||||||
// },
|
text: content.value,
|
||||||
// InlayHintTooltip::MarkupContent(content) => {
|
kind: content.kind,
|
||||||
// HoverBlock {
|
}
|
||||||
// text: content.value,
|
}
|
||||||
// kind: content.kind,
|
},
|
||||||
// }
|
range: InlayHighlight {
|
||||||
// }
|
inlay: hovered_hint.id,
|
||||||
// },
|
inlay_position: hovered_hint.position,
|
||||||
// range: InlayHighlight {
|
range: extra_shift_left
|
||||||
// inlay: hovered_hint.id,
|
..hovered_hint.text.len() + extra_shift_right,
|
||||||
// inlay_position: hovered_hint.position,
|
},
|
||||||
// range: extra_shift_left
|
},
|
||||||
// ..hovered_hint.text.len() + extra_shift_right,
|
cx,
|
||||||
// },
|
);
|
||||||
// },
|
hover_updated = true;
|
||||||
// cx,
|
}
|
||||||
// );
|
}
|
||||||
// hover_updated = true;
|
project::InlayHintLabel::LabelParts(label_parts) => {
|
||||||
// }
|
let hint_start =
|
||||||
// }
|
snapshot.anchor_to_inlay_offset(hovered_hint.position);
|
||||||
// project::InlayHintLabel::LabelParts(label_parts) => {
|
if let Some((hovered_hint_part, part_range)) =
|
||||||
// let hint_start =
|
hover_popover::find_hovered_hint_part(
|
||||||
// snapshot.anchor_to_inlay_offset(hovered_hint.position);
|
label_parts,
|
||||||
// if let Some((hovered_hint_part, part_range)) =
|
hint_start,
|
||||||
// hover_popover::find_hovered_hint_part(
|
hovered_offset,
|
||||||
// label_parts,
|
)
|
||||||
// hint_start,
|
{
|
||||||
// hovered_offset,
|
let highlight_start =
|
||||||
// )
|
(part_range.start - hint_start).0 + extra_shift_left;
|
||||||
// {
|
let highlight_end =
|
||||||
// let highlight_start =
|
(part_range.end - hint_start).0 + extra_shift_right;
|
||||||
// (part_range.start - hint_start).0 + extra_shift_left;
|
let highlight = InlayHighlight {
|
||||||
// let highlight_end =
|
inlay: hovered_hint.id,
|
||||||
// (part_range.end - hint_start).0 + extra_shift_right;
|
inlay_position: hovered_hint.position,
|
||||||
// let highlight = InlayHighlight {
|
range: highlight_start..highlight_end,
|
||||||
// inlay: hovered_hint.id,
|
};
|
||||||
// inlay_position: hovered_hint.position,
|
if let Some(tooltip) = hovered_hint_part.tooltip {
|
||||||
// range: highlight_start..highlight_end,
|
hover_popover::hover_at_inlay(
|
||||||
// };
|
editor,
|
||||||
// if let Some(tooltip) = hovered_hint_part.tooltip {
|
InlayHover {
|
||||||
// hover_popover::hover_at_inlay(
|
excerpt: excerpt_id,
|
||||||
// editor,
|
tooltip: match tooltip {
|
||||||
// InlayHover {
|
InlayHintLabelPartTooltip::String(text) => {
|
||||||
// excerpt: excerpt_id,
|
HoverBlock {
|
||||||
// tooltip: match tooltip {
|
text,
|
||||||
// InlayHintLabelPartTooltip::String(text) => {
|
kind: HoverBlockKind::PlainText,
|
||||||
// HoverBlock {
|
}
|
||||||
// text,
|
}
|
||||||
// kind: HoverBlockKind::PlainText,
|
InlayHintLabelPartTooltip::MarkupContent(
|
||||||
// }
|
content,
|
||||||
// }
|
) => HoverBlock {
|
||||||
// InlayHintLabelPartTooltip::MarkupContent(
|
text: content.value,
|
||||||
// content,
|
kind: content.kind,
|
||||||
// ) => HoverBlock {
|
},
|
||||||
// text: content.value,
|
},
|
||||||
// kind: content.kind,
|
range: highlight.clone(),
|
||||||
// },
|
},
|
||||||
// },
|
cx,
|
||||||
// range: highlight.clone(),
|
);
|
||||||
// },
|
hover_updated = true;
|
||||||
// cx,
|
}
|
||||||
// );
|
if let Some((language_server_id, location)) =
|
||||||
// hover_updated = true;
|
hovered_hint_part.location
|
||||||
// }
|
{
|
||||||
// if let Some((language_server_id, location)) =
|
go_to_definition_updated = true;
|
||||||
// hovered_hint_part.location
|
update_go_to_definition_link(
|
||||||
// {
|
editor,
|
||||||
// go_to_definition_updated = true;
|
Some(GoToDefinitionTrigger::InlayHint(
|
||||||
// update_go_to_definition_link(
|
highlight,
|
||||||
// editor,
|
location,
|
||||||
// Some(GoToDefinitionTrigger::InlayHint(
|
language_server_id,
|
||||||
// highlight,
|
)),
|
||||||
// location,
|
cmd_held,
|
||||||
// language_server_id,
|
shift_held,
|
||||||
// )),
|
cx,
|
||||||
// cmd_held,
|
);
|
||||||
// shift_held,
|
}
|
||||||
// cx,
|
}
|
||||||
// );
|
}
|
||||||
// }
|
};
|
||||||
// }
|
}
|
||||||
// }
|
ResolveState::Resolving => {}
|
||||||
// };
|
}
|
||||||
// }
|
}
|
||||||
// ResolveState::Resolving => {}
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if !go_to_definition_updated {
|
if !go_to_definition_updated {
|
||||||
// update_go_to_definition_link(editor, None, cmd_held, shift_held, cx);
|
update_go_to_definition_link(editor, None, cmd_held, shift_held, cx);
|
||||||
// }
|
}
|
||||||
// if !hover_updated {
|
if !hover_updated {
|
||||||
// hover_popover::hover_at(editor, None, cx);
|
hover_popover::hover_at(editor, None, cx);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum LinkDefinitionKind {
|
pub enum LinkDefinitionKind {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue