Add a way to toggle inlay hints with modifiers (#25752)
This commit is contained in:
parent
2e98bc17cb
commit
e8ef36edcc
10 changed files with 101 additions and 9 deletions
|
@ -711,6 +711,7 @@ pub struct Editor {
|
|||
edit_prediction_indent_conflict: bool,
|
||||
edit_prediction_requires_modifier_in_indent_conflict: bool,
|
||||
inlay_hint_cache: InlayHintCache,
|
||||
inlay_hint_modifiers_toggled: bool,
|
||||
next_inlay_id: usize,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
pixel_position_of_newest_cursor: Option<gpui::Point<Pixels>>,
|
||||
|
@ -1419,6 +1420,7 @@ impl Editor {
|
|||
released_too_fast: false,
|
||||
},
|
||||
inline_diagnostics_enabled: mode == EditorMode::Full,
|
||||
inlay_hint_modifiers_toggled: false,
|
||||
inlay_hint_cache: InlayHintCache::new(inlay_hint_settings),
|
||||
|
||||
gutter_hovered: false,
|
||||
|
@ -3691,6 +3693,9 @@ impl Editor {
|
|||
);
|
||||
let (invalidate_cache, required_languages) = match reason {
|
||||
InlayHintRefreshReason::Toggle(enabled) => {
|
||||
if self.inlay_hint_cache.enabled == enabled {
|
||||
return;
|
||||
}
|
||||
self.inlay_hint_cache.enabled = enabled;
|
||||
if enabled {
|
||||
(InvalidationStrategy::RefreshRequested, None)
|
||||
|
|
|
@ -12,6 +12,7 @@ use crate::{
|
|||
hover_popover::{
|
||||
self, hover_at, HOVER_POPOVER_GAP, MIN_POPOVER_CHARACTER_WIDTH, MIN_POPOVER_LINE_HEIGHT,
|
||||
},
|
||||
inlay_hint_settings,
|
||||
items::BufferSearchHighlights,
|
||||
mouse_context_menu::{self, MenuPosition, MouseContextMenu},
|
||||
scroll::{axis_pair, scroll_amount::ScrollAmount, AxisPair},
|
||||
|
@ -19,10 +20,11 @@ use crate::{
|
|||
DisplayRow, DocumentHighlightRead, DocumentHighlightWrite, EditDisplayMode, Editor, EditorMode,
|
||||
EditorSettings, EditorSnapshot, EditorStyle, ExpandExcerpts, FocusedBlock, GoToHunk,
|
||||
GoToPrevHunk, GutterDimensions, HalfPageDown, HalfPageUp, HandleInput, HoveredCursor,
|
||||
InlineCompletion, JumpData, LineDown, LineUp, OpenExcerpts, PageDown, PageUp, Point, RowExt,
|
||||
RowRangeExt, SelectPhase, SelectedTextHighlight, Selection, SoftWrap, StickyHeaderExcerpt,
|
||||
ToPoint, ToggleFold, COLUMNAR_SELECTION_MODIFIERS, CURSORS_VISIBLE_FOR, FILE_HEADER_HEIGHT,
|
||||
GIT_BLAME_MAX_AUTHOR_CHARS_DISPLAYED, MAX_LINE_LEN, MULTI_BUFFER_EXCERPT_HEADER_HEIGHT,
|
||||
InlayHintRefreshReason, InlineCompletion, JumpData, LineDown, LineUp, OpenExcerpts, PageDown,
|
||||
PageUp, Point, RowExt, RowRangeExt, SelectPhase, SelectedTextHighlight, Selection, SoftWrap,
|
||||
StickyHeaderExcerpt, ToPoint, ToggleFold, COLUMNAR_SELECTION_MODIFIERS, CURSORS_VISIBLE_FOR,
|
||||
FILE_HEADER_HEIGHT, GIT_BLAME_MAX_AUTHOR_CHARS_DISPLAYED, MAX_LINE_LEN,
|
||||
MULTI_BUFFER_EXCERPT_HEADER_HEIGHT,
|
||||
};
|
||||
use buffer_diff::{DiffHunkSecondaryStatus, DiffHunkStatus, DiffHunkStatusKind};
|
||||
use client::ParticipantIndex;
|
||||
|
@ -505,6 +507,30 @@ impl EditorElement {
|
|||
return;
|
||||
}
|
||||
editor.update(cx, |editor, cx| {
|
||||
let inlay_hint_settings = inlay_hint_settings(
|
||||
editor.selections.newest_anchor().head(),
|
||||
&editor.buffer.read(cx).snapshot(cx),
|
||||
cx,
|
||||
);
|
||||
|
||||
if let Some(inlay_modifiers) =
|
||||
inlay_hint_settings.toggle_on_modifiers_press.as_ref()
|
||||
{
|
||||
if inlay_modifiers == &event.modifiers {
|
||||
editor.refresh_inlay_hints(
|
||||
InlayHintRefreshReason::Toggle(!editor.inlay_hints_enabled()),
|
||||
cx,
|
||||
);
|
||||
editor.inlay_hint_modifiers_toggled = true;
|
||||
} else if editor.inlay_hint_modifiers_toggled {
|
||||
editor.refresh_inlay_hints(
|
||||
InlayHintRefreshReason::Toggle(!editor.inlay_hints_enabled()),
|
||||
cx,
|
||||
);
|
||||
editor.inlay_hint_modifiers_toggled = false;
|
||||
}
|
||||
}
|
||||
|
||||
if editor.hover_state.focused(window, cx) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1271,6 +1271,7 @@ mod tests {
|
|||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
|
||||
|
|
|
@ -1536,6 +1536,7 @@ mod tests {
|
|||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
|
||||
|
|
|
@ -1288,6 +1288,7 @@ pub mod tests {
|
|||
show_parameter_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: allowed_hint_kinds.contains(&None),
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
let (_, editor, fake_server) = prepare_test_objects(cx, |fake_server, file_with_hints| {
|
||||
|
@ -1391,6 +1392,7 @@ pub mod tests {
|
|||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -1493,6 +1495,7 @@ pub mod tests {
|
|||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -1712,6 +1715,7 @@ pub mod tests {
|
|||
show_parameter_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: allowed_hint_kinds.contains(&None),
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -1871,6 +1875,7 @@ pub mod tests {
|
|||
.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: new_allowed_hint_kinds.contains(&None),
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
cx.executor().run_until_parked();
|
||||
|
@ -1913,6 +1918,7 @@ pub mod tests {
|
|||
.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: another_allowed_hint_kinds.contains(&None),
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
cx.executor().run_until_parked();
|
||||
|
@ -1967,6 +1973,7 @@ pub mod tests {
|
|||
.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: final_allowed_hint_kinds.contains(&None),
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
cx.executor().run_until_parked();
|
||||
|
@ -2038,6 +2045,7 @@ pub mod tests {
|
|||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -2169,6 +2177,7 @@ pub mod tests {
|
|||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -2467,6 +2476,7 @@ pub mod tests {
|
|||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -2811,6 +2821,7 @@ pub mod tests {
|
|||
show_parameter_hints: false,
|
||||
show_other_hints: false,
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -2992,6 +3003,7 @@ pub mod tests {
|
|||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
cx.executor().run_until_parked();
|
||||
|
@ -3023,6 +3035,7 @@ pub mod tests {
|
|||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -3114,6 +3127,7 @@ pub mod tests {
|
|||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
|
||||
|
@ -3187,6 +3201,7 @@ pub mod tests {
|
|||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
cx.executor().run_until_parked();
|
||||
|
@ -3246,6 +3261,7 @@ pub mod tests {
|
|||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
toggle_on_modifiers_press: None,
|
||||
})
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue