History

uncomment mouse moved

Piotr Osiewicz committed 3 years ago

Commit cd377351 parent e4bc0322 files · +225 −212Browse files

Unified · Split

2 files
  1. crates/editor2/src/element.rs +62 −46
  2. crates/editor2/src/link_go_to_definition.rs +163 −166
crates/editor2/src/element.rs+62−46
@@ -2,6 +2,10 @@ use crate::{ · 1 unmodified line
22 display_map::{BlockStyle, DisplaySnapshot, FoldStatus, HighlightedChunk, ToDisplayPoint},
33 editor_settings::ShowScrollbar,
44 git::{diff_hunk_to_display, DisplayDiffHunk},
5+ hover_popover::hover_at,
6+ link_go_to_definition::{
7+ update_go_to_definition_link, update_inlay_link_and_hover_points, GoToDefinitionTrigger,
8+ },
59 scroll::scroll_amount::ScrollAmount,
610 CursorShape, DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle,
711 HalfPageDown, HalfPageUp, LineDown, LineUp, MoveDown, PageDown, PageUp, Point, Selection,
@@ -12,9 +16,9 @@ use collections::{BTreeMap, HashMap}; · 4 unmodified lines
1216 use gpui::{
1317 black, hsla, point, px, relative, size, transparent_black, Action, AnyElement,
1418 BorrowAppContext, BorrowWindow, Bounds, ContentMask, Corners, DispatchContext, DispatchPhase,
15− Edges, Element, ElementId, Entity, Hsla, KeyDownEvent, KeyListener, KeyMatch, Line, Pixels,
16− ScrollWheelEvent, ShapedGlyph, Size, StatefulInteraction, Style, TextRun, TextStyle,
17− TextSystem, ViewContext, WindowContext,
19+ Edges, Element, ElementId, Entity, Hsla, KeyDownEvent, KeyListener, KeyMatch, Line, Modifiers,
20+ MouseMoveEvent, Pixels, ScrollWheelEvent, ShapedGlyph, Size, StatefulInteraction, Style,
21+ TextRun, TextStyle, TextSystem, ViewContext, WindowContext,
1822 };
1923 use itertools::Itertools;
2024 use language::language_settings::ShowWhitespaceSetting;
@@ -423,50 +427,50 @@ impl EditorElement { · 402 unmodified lines
423427 // }
424428 // }
425429
426− // fn mouse_moved(
427− // editor: &mut Editor,
428− // MouseMovedEvent {
429− // modifiers: Modifiers { shift, cmd, .. },
430− // position,
431− // ..
432− // }: MouseMovedEvent,
433− // position_map: &PositionMap,
434− // text_bounds: Bounds<Pixels>,
435− // cx: &mut ViewContext<Editor>,
436− // ) -> bool {
437− // // This will be handled more correctly once https://github.com/zed-industries/zed/issues/1218 is completed
438− // // Don't trigger hover popover if mouse is hovering over context menu
439− // if text_bounds.contains_point(position) {
440− // let point_for_position = position_map.point_for_position(text_bounds, position);
441− // match point_for_position.as_valid() {
442− // Some(point) => {
443− // update_go_to_definition_link(
444− // editor,
445− // Some(GoToDefinitionTrigger::Text(point)),
446− // cmd,
447− // shift,
448− // cx,
449− // );
450− // hover_at(editor, Some(point), cx);
451− // }
452− // None => {
453− // update_inlay_link_and_hover_points(
454− // &position_map.snapshot,
455− // point_for_position,
456− // editor,
457− // cmd,
458− // shift,
459− // cx,
460− // );
461− // }
462− // }
463− // } else {
464− // update_go_to_definition_link(editor, None, cmd, shift, cx);
465− // hover_at(editor, None, cx);
466− // }
430+ fn mouse_moved(
431+ editor: &mut Editor,
432+ MouseMoveEvent {
433+ modifiers: Modifiers { shift, command, .. },
434+ position,
435+ ..
436+ }: &MouseMoveEvent,
437+ position_map: &PositionMap,
438+ text_bounds: Bounds<Pixels>,
439+ cx: &mut ViewContext<Editor>,
440+ ) -> bool {
441+ // This will be handled more correctly once https://github.com/zed-industries/zed/issues/1218 is completed
442+ // Don't trigger hover popover if mouse is hovering over context menu
443+ if text_bounds.contains_point(position) {
444+ let point_for_position = position_map.point_for_position(text_bounds, position.clone());
445+ match point_for_position.as_valid() {
446+ Some(point) => {
447+ update_go_to_definition_link(
448+ editor,
449+ Some(GoToDefinitionTrigger::Text(point)),
450+ *command,
451+ *shift,
452+ cx,
453+ );
454+ hover_at(editor, Some(point), cx);
455+ }
456+ None => {
457+ update_inlay_link_and_hover_points(
458+ &position_map.snapshot,
459+ point_for_position,
460+ editor,
461+ *command,
462+ *shift,
463+ cx,
464+ );
465+ }
466+ }
467+ } else {
468+ update_go_to_definition_link(editor, None, *command, *shift, cx);
469+ hover_at(editor, None, cx);
470+ }
467471
468− // true
469− // }
472+ true
473+ }
470474
471475 fn scroll(
472476 editor: &mut Editor,
@@ -2772,6 +2776,18 @@ impl Element<Editor> for EditorElement { · 2299 unmodified lines
27722776 }
27732777 }
27742778 });
2779+ cx.on_mouse_event({
2780+ let position_map = layout.position_map.clone();
2781+ move |editor, event: &MouseMoveEvent, phase, cx| {
2782+ if phase != DispatchPhase::Bubble {
2783+ return;
2784+ }
2785+
2786+ if Self::mouse_moved(editor, event, &position_map, bounds, cx) {
2787+ cx.stop_propagation()
2788+ }
2789+ }
2790+ });
27752791
27762792 if editor.focus_handle.is_focused(cx) {
27772793 cx.handle_text_input();
crates/editor2/src/link_go_to_definition.rs+163−166
@@ -171,173 +171,170 @@ pub fn update_inlay_link_and_hover_points( · 170 unmodified lines
171171 shift_held: bool,
172172 cx: &mut ViewContext<'_, Editor>,
173173 ) {
174− todo!("old implementation below")
175−}
176−// ) {
177−// let hovered_offset = if point_for_position.column_overshoot_after_line_end == 0 {
178−// Some(snapshot.display_point_to_inlay_offset(point_for_position.exact_unclipped, Bias::Left))
179−// } else {
180−// None
181−// };
182−// let mut go_to_definition_updated = false;
183−// let mut hover_updated = false;
184−// if let Some(hovered_offset) = hovered_offset {
185−// let buffer_snapshot = editor.buffer().read(cx).snapshot(cx);
186−// let previous_valid_anchor = buffer_snapshot.anchor_at(
187−// point_for_position.previous_valid.to_point(snapshot),
188−// Bias::Left,
189−// );
190−// let next_valid_anchor = buffer_snapshot.anchor_at(
191−// point_for_position.next_valid.to_point(snapshot),
192−// Bias::Right,
193−// );
194−// if let Some(hovered_hint) = editor
195−// .visible_inlay_hints(cx)
196−// .into_iter()
197−// .skip_while(|hint| {
198−// hint.position
199−// .cmp(&previous_valid_anchor, &buffer_snapshot)
200−// .is_lt()
201−// })
202−// .take_while(|hint| {
203−// hint.position
204−// .cmp(&next_valid_anchor, &buffer_snapshot)
205−// .is_le()
206−// })
207−// .max_by_key(|hint| hint.id)
208−// {
209−// let inlay_hint_cache = editor.inlay_hint_cache();
210−// let excerpt_id = previous_valid_anchor.excerpt_id;
211−// if let Some(cached_hint) = inlay_hint_cache.hint_by_id(excerpt_id, hovered_hint.id) {
212−// match cached_hint.resolve_state {
213−// ResolveState::CanResolve(_, _) => {
214−// if let Some(buffer_id) = previous_valid_anchor.buffer_id {
215−// inlay_hint_cache.spawn_hint_resolve(
216−// buffer_id,
217−// excerpt_id,
218−// hovered_hint.id,
219−// cx,
220−// );
221−// }
222−// }
223−// ResolveState::Resolved => {
224−// let mut extra_shift_left = 0;
225−// let mut extra_shift_right = 0;
226−// if cached_hint.padding_left {
227−// extra_shift_left += 1;
228−// extra_shift_right += 1;
229−// }
230−// if cached_hint.padding_right {
231−// extra_shift_right += 1;
232−// }
233−// match cached_hint.label {
234−// project::InlayHintLabel::String(_) => {
235−// if let Some(tooltip) = cached_hint.tooltip {
236−// hover_popover::hover_at_inlay(
237−// editor,
238−// InlayHover {
239−// excerpt: excerpt_id,
240−// tooltip: match tooltip {
241−// InlayHintTooltip::String(text) => HoverBlock {
242−// text,
243−// kind: HoverBlockKind::PlainText,
244−// },
245−// InlayHintTooltip::MarkupContent(content) => {
246−// HoverBlock {
247−// text: content.value,
248−// kind: content.kind,
249−// }
250−// }
251−// },
252−// range: InlayHighlight {
253−// inlay: hovered_hint.id,
254−// inlay_position: hovered_hint.position,
255−// range: extra_shift_left
256−// ..hovered_hint.text.len() + extra_shift_right,
257−// },
258−// },
259−// cx,
260−// );
261−// hover_updated = true;
262−// }
263−// }
264−// project::InlayHintLabel::LabelParts(label_parts) => {
265−// let hint_start =
266−// snapshot.anchor_to_inlay_offset(hovered_hint.position);
267−// if let Some((hovered_hint_part, part_range)) =
268−// hover_popover::find_hovered_hint_part(
269−// label_parts,
270−// hint_start,
271−// hovered_offset,
272−// )
273−// {
274−// let highlight_start =
275−// (part_range.start - hint_start).0 + extra_shift_left;
276−// let highlight_end =
277−// (part_range.end - hint_start).0 + extra_shift_right;
278−// let highlight = InlayHighlight {
279−// inlay: hovered_hint.id,
280−// inlay_position: hovered_hint.position,
281−// range: highlight_start..highlight_end,
282−// };
283−// if let Some(tooltip) = hovered_hint_part.tooltip {
284−// hover_popover::hover_at_inlay(
285−// editor,
286−// InlayHover {
287−// excerpt: excerpt_id,
288−// tooltip: match tooltip {
289−// InlayHintLabelPartTooltip::String(text) => {
290−// HoverBlock {
291−// text,
292−// kind: HoverBlockKind::PlainText,
293−// }
294−// }
295−// InlayHintLabelPartTooltip::MarkupContent(
296−// content,
297−// ) => HoverBlock {
298−// text: content.value,
299−// kind: content.kind,
300−// },
301−// },
302−// range: highlight.clone(),
303−// },
304−// cx,
305−// );
306−// hover_updated = true;
307−// }
308−// if let Some((language_server_id, location)) =
309−// hovered_hint_part.location
310−// {
311−// go_to_definition_updated = true;
312−// update_go_to_definition_link(
313−// editor,
314−// Some(GoToDefinitionTrigger::InlayHint(
315−// highlight,
316−// location,
317−// language_server_id,
318−// )),
319−// cmd_held,
320−// shift_held,
321−// cx,
322−// );
323−// }
324−// }
325−// }
326−// };
327−// }
328−// ResolveState::Resolving => {}
329−// }
330−// }
331−// }
332−// }
174+ let hovered_offset = if point_for_position.column_overshoot_after_line_end == 0 {
175+ Some(snapshot.display_point_to_inlay_offset(point_for_position.exact_unclipped, Bias::Left))
176+ } else {
177+ None
178+ };
179+ let mut go_to_definition_updated = false;
180+ let mut hover_updated = false;
181+ if let Some(hovered_offset) = hovered_offset {
182+ let buffer_snapshot = editor.buffer().read(cx).snapshot(cx);
183+ let previous_valid_anchor = buffer_snapshot.anchor_at(
184+ point_for_position.previous_valid.to_point(snapshot),
185+ Bias::Left,
186+ );
187+ let next_valid_anchor = buffer_snapshot.anchor_at(
188+ point_for_position.next_valid.to_point(snapshot),
189+ Bias::Right,
190+ );
191+ if let Some(hovered_hint) = editor
192+ .visible_inlay_hints(cx)
193+ .into_iter()
194+ .skip_while(|hint| {
195+ hint.position
196+ .cmp(&previous_valid_anchor, &buffer_snapshot)
197+ .is_lt()
198+ })
199+ .take_while(|hint| {
200+ hint.position
201+ .cmp(&next_valid_anchor, &buffer_snapshot)
202+ .is_le()
203+ })
204+ .max_by_key(|hint| hint.id)
205+ {
206+ let inlay_hint_cache = editor.inlay_hint_cache();
207+ let excerpt_id = previous_valid_anchor.excerpt_id;
208+ if let Some(cached_hint) = inlay_hint_cache.hint_by_id(excerpt_id, hovered_hint.id) {
209+ match cached_hint.resolve_state {
210+ ResolveState::CanResolve(_, _) => {
211+ if let Some(buffer_id) = previous_valid_anchor.buffer_id {
212+ inlay_hint_cache.spawn_hint_resolve(
213+ buffer_id,
214+ excerpt_id,
215+ hovered_hint.id,
216+ cx,
217+ );
218+ }
219+ }
220+ ResolveState::Resolved => {
221+ let mut extra_shift_left = 0;
222+ let mut extra_shift_right = 0;
223+ if cached_hint.padding_left {
224+ extra_shift_left += 1;
225+ extra_shift_right += 1;
226+ }
227+ if cached_hint.padding_right {
228+ extra_shift_right += 1;
229+ }
230+ match cached_hint.label {
231+ project::InlayHintLabel::String(_) => {
232+ if let Some(tooltip) = cached_hint.tooltip {
233+ hover_popover::hover_at_inlay(
234+ editor,
235+ InlayHover {
236+ excerpt: excerpt_id,
237+ tooltip: match tooltip {
238+ InlayHintTooltip::String(text) => HoverBlock {
239+ text,
240+ kind: HoverBlockKind::PlainText,
241+ },
242+ InlayHintTooltip::MarkupContent(content) => {
243+ HoverBlock {
244+ text: content.value,
245+ kind: content.kind,
246+ }
247+ }
248+ },
249+ range: InlayHighlight {
250+ inlay: hovered_hint.id,
251+ inlay_position: hovered_hint.position,
252+ range: extra_shift_left
253+ ..hovered_hint.text.len() + extra_shift_right,
254+ },
255+ },
256+ cx,
257+ );
258+ hover_updated = true;
259+ }
260+ }
261+ project::InlayHintLabel::LabelParts(label_parts) => {
262+ let hint_start =
263+ snapshot.anchor_to_inlay_offset(hovered_hint.position);
264+ if let Some((hovered_hint_part, part_range)) =
265+ hover_popover::find_hovered_hint_part(
266+ label_parts,
267+ hint_start,
268+ hovered_offset,
269+ )
270+ {
271+ let highlight_start =
272+ (part_range.start - hint_start).0 + extra_shift_left;
273+ let highlight_end =
274+ (part_range.end - hint_start).0 + extra_shift_right;
275+ let highlight = InlayHighlight {
276+ inlay: hovered_hint.id,
277+ inlay_position: hovered_hint.position,
278+ range: highlight_start..highlight_end,
279+ };
280+ if let Some(tooltip) = hovered_hint_part.tooltip {
281+ hover_popover::hover_at_inlay(
282+ editor,
283+ InlayHover {
284+ excerpt: excerpt_id,
285+ tooltip: match tooltip {
286+ InlayHintLabelPartTooltip::String(text) => {
287+ HoverBlock {
288+ text,
289+ kind: HoverBlockKind::PlainText,
290+ }
291+ }
292+ InlayHintLabelPartTooltip::MarkupContent(
293+ content,
294+ ) => HoverBlock {
295+ text: content.value,
296+ kind: content.kind,
297+ },
298+ },
299+ range: highlight.clone(),
300+ },
301+ cx,
302+ );
303+ hover_updated = true;
304+ }
305+ if let Some((language_server_id, location)) =
306+ hovered_hint_part.location
307+ {
308+ go_to_definition_updated = true;
309+ update_go_to_definition_link(
310+ editor,
311+ Some(GoToDefinitionTrigger::InlayHint(
312+ highlight,
313+ location,
314+ language_server_id,
315+ )),
316+ cmd_held,
317+ shift_held,
318+ cx,
319+ );
320+ }
321+ }
322+ }
323+ };
324+ }
325+ ResolveState::Resolving => {}
326+ }
327+ }
328+ }
329+ }
333330
334−// if !go_to_definition_updated {
335−// update_go_to_definition_link(editor, None, cmd_held, shift_held, cx);
336−// }
337−// if !hover_updated {
338−// hover_popover::hover_at(editor, None, cx);
339−// }
340−// }
331+ if !go_to_definition_updated {
332+ update_go_to_definition_link(editor, None, cmd_held, shift_held, cx);
333+ }
334+ if !hover_updated {
335+ hover_popover::hover_at(editor, None, cx);
336+ }
337+}
341338
342339 #[derive(Debug, Clone, Copy, PartialEq)]
343340 pub enum LinkDefinitionKind {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t