Skip to content

Commit

Permalink
Fix markdown link tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
someone13574 committed Feb 13, 2025
1 parent 7651404 commit cda99cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions crates/gpui/src/elements/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ impl Element for InteractiveText {
|interactive_state, window| {
let mut interactive_state = interactive_state.unwrap_or_default();
if let Some(click_listener) = self.click_listener.take() {
let mouse_position = window.mouse_position();
let mouse_position = window.mouse_position() - window.element_origin();
if let Ok(ix) = text_layout.index_for_position(mouse_position) {
if self
.clickable_ranges
Expand Down Expand Up @@ -744,9 +744,10 @@ impl Element for InteractiveText {
let build_tooltip = Rc::new({
let tooltip_is_hoverable = false;
let text_layout = text_layout.clone();
let origin = window.element_origin();
move |window: &mut Window, cx: &mut App| {
text_layout
.index_for_position(window.mouse_position())
.index_for_position(window.mouse_position() - origin)
.ok()
.and_then(|position| tooltip_builder(position, window, cx))
.map(|view| (view, tooltip_is_hoverable))
Expand All @@ -758,11 +759,12 @@ impl Element for InteractiveText {
let source_bounds = hitbox.bounds;
let text_layout = text_layout.clone();
let pending_mouse_down = interactive_state.mouse_down_index.clone();
let origin = window.element_origin();
move |window: &Window| {
text_layout
.index_for_position(window.mouse_position())
.index_for_position(window.mouse_position() - origin)
.is_ok()
&& source_bounds.contains(&window.mouse_position())
&& source_bounds.contains(&(window.mouse_position() - origin))
&& pending_mouse_down.get().is_none()
}
});
Expand All @@ -771,9 +773,10 @@ impl Element for InteractiveText {
let hitbox = hitbox.clone();
let text_layout = text_layout.clone();
let pending_mouse_down = interactive_state.mouse_down_index.clone();
let origin = window.element_origin();
move |window: &Window| {
text_layout
.index_for_position(window.mouse_position())
.index_for_position(window.mouse_position() - origin)
.is_ok()
&& hitbox.is_hovered(window)
&& pending_mouse_down.get().is_none()
Expand Down
2 changes: 1 addition & 1 deletion crates/markdown/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ impl MarkdownElement {
let is_hovering_link = hitbox.is_hovered(window)
&& !self.markdown.read(cx).selection.pending
&& rendered_text
.link_for_position(window.mouse_position())
.link_for_position(window.mouse_position() - window.element_origin())
.is_some();

if is_hovering_link {
Expand Down

0 comments on commit cda99cc

Please sign in to comment.