mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-27 04:44:30 +00:00
Better highlight hint ranges
This commit is contained in:
parent
5cf51211b6
commit
dad64edde1
2 changed files with 16 additions and 30 deletions
|
@ -57,8 +57,6 @@ pub struct InlayHover {
|
|||
|
||||
pub fn find_hovered_hint_part(
|
||||
label_parts: Vec<InlayHintLabelPart>,
|
||||
padding_left: bool,
|
||||
padding_right: bool,
|
||||
hint_range: Range<InlayOffset>,
|
||||
hovered_offset: InlayOffset,
|
||||
) -> Option<(InlayHintLabelPart, Range<InlayOffset>)> {
|
||||
|
@ -67,19 +65,11 @@ pub fn find_hovered_hint_part(
|
|||
let mut part_start = hint_range.start;
|
||||
for part in label_parts {
|
||||
let part_len = part.value.chars().count();
|
||||
if hovered_character >= part_len {
|
||||
if hovered_character > part_len {
|
||||
hovered_character -= part_len;
|
||||
part_start.0 += part_len;
|
||||
} else {
|
||||
let mut part_end = InlayOffset(part_start.0 + part_len);
|
||||
if padding_left {
|
||||
part_start.0 += 1;
|
||||
part_end.0 += 1;
|
||||
}
|
||||
if padding_right {
|
||||
part_start.0 += 1;
|
||||
part_end.0 += 1;
|
||||
}
|
||||
let part_end = InlayOffset(part_start.0 + part_len);
|
||||
return Some((part, part_start..part_end));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -165,11 +165,8 @@ pub fn update_inlay_link_and_hover_points(
|
|||
snapshot.display_point_to_inlay_offset(point_for_position.previous_valid, Bias::Left);
|
||||
let hint_end_offset =
|
||||
snapshot.display_point_to_inlay_offset(point_for_position.next_valid, Bias::Right);
|
||||
let offset_overshoot = point_for_position.column_overshoot_after_line_end as usize;
|
||||
let hovered_offset = if offset_overshoot == 0 {
|
||||
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 if (hint_end_offset - hint_start_offset).0 >= offset_overshoot {
|
||||
Some(InlayOffset(hint_start_offset.0 + offset_overshoot))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -215,17 +212,18 @@ pub fn update_inlay_link_and_hover_points(
|
|||
}
|
||||
}
|
||||
ResolveState::Resolved => {
|
||||
let mut actual_hint_start = hint_start_offset;
|
||||
let mut actual_hint_end = hint_end_offset;
|
||||
if cached_hint.padding_left {
|
||||
actual_hint_start.0 += 1;
|
||||
actual_hint_end.0 += 1;
|
||||
}
|
||||
if cached_hint.padding_right {
|
||||
actual_hint_start.0 += 1;
|
||||
actual_hint_end.0 += 1;
|
||||
}
|
||||
match cached_hint.label {
|
||||
project::InlayHintLabel::String(_) => {
|
||||
let mut highlight_start = hint_start_offset;
|
||||
let mut highlight_end = hint_end_offset;
|
||||
if cached_hint.padding_left {
|
||||
highlight_start.0 += 1;
|
||||
highlight_end.0 += 1;
|
||||
}
|
||||
if cached_hint.padding_right {
|
||||
highlight_end.0 -= 1;
|
||||
}
|
||||
if let Some(tooltip) = cached_hint.tooltip {
|
||||
hover_popover::hover_at_inlay(
|
||||
editor,
|
||||
|
@ -246,8 +244,8 @@ pub fn update_inlay_link_and_hover_points(
|
|||
triggered_from: hovered_offset,
|
||||
range: InlayRange {
|
||||
inlay_position: hovered_hint.position,
|
||||
highlight_start,
|
||||
highlight_end,
|
||||
highlight_start: actual_hint_start,
|
||||
highlight_end: actual_hint_end,
|
||||
},
|
||||
},
|
||||
cx,
|
||||
|
@ -259,9 +257,7 @@ pub fn update_inlay_link_and_hover_points(
|
|||
if let Some((hovered_hint_part, part_range)) =
|
||||
hover_popover::find_hovered_hint_part(
|
||||
label_parts,
|
||||
cached_hint.padding_left,
|
||||
cached_hint.padding_right,
|
||||
hint_start_offset..hint_end_offset,
|
||||
actual_hint_start..actual_hint_end,
|
||||
hovered_offset,
|
||||
)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue