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