Add a keybinding to the Go to Line button (#21350)

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2024-11-30 00:50:38 +02:00 committed by GitHub
parent 5f29f214c3
commit 57a45d80ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,5 +1,5 @@
use editor::{Editor, ToPoint};
use gpui::{AppContext, Subscription, Task, View, WeakView};
use gpui::{AppContext, FocusHandle, FocusableView, Subscription, Task, View, WeakView};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsSources};
@ -22,6 +22,7 @@ pub(crate) struct SelectionStats {
pub struct CursorPosition {
position: Option<Point>,
selected_count: SelectionStats,
context: Option<FocusHandle>,
workspace: WeakView<Workspace>,
update_position: Task<()>,
_observe_active_editor: Option<Subscription>,
@ -31,6 +32,7 @@ impl CursorPosition {
pub fn new(workspace: &Workspace) -> Self {
Self {
position: None,
context: None,
selected_count: Default::default(),
workspace: workspace.weak_handle(),
update_position: Task::ready(()),
@ -58,7 +60,8 @@ impl CursorPosition {
match editor.mode() {
editor::EditorMode::AutoHeight { .. }
| editor::EditorMode::SingleLine { .. } => {
cursor_position.position = None
cursor_position.position = None;
cursor_position.context = None;
}
editor::EditorMode::Full => {
let mut last_selection = None::<Selection<usize>>;
@ -87,6 +90,7 @@ impl CursorPosition {
}
cursor_position.position =
last_selection.map(|s| s.head().to_point(&buffer));
cursor_position.context = Some(editor.focus_handle(cx));
}
}
@ -158,6 +162,8 @@ impl Render for CursorPosition {
);
self.write_position(&mut text, cx);
let context = self.context.clone();
el.child(
Button::new("go-to-line-column", text)
.label_size(LabelSize::Small)
@ -174,12 +180,18 @@ impl Render for CursorPosition {
});
}
}))
.tooltip(|cx| {
Tooltip::for_action(
.tooltip(move |cx| match context.as_ref() {
Some(context) => Tooltip::for_action_in(
"Go to Line/Column",
&editor::actions::ToggleGoToLine,
context,
cx,
),
None => Tooltip::for_action(
"Go to Line/Column",
&editor::actions::ToggleGoToLine,
cx,
)
),
}),
)
})