Skip to content

Commit 57a45d8

Browse files
Add a keybinding to the Go to Line button (#21350)
Release Notes: - N/A
1 parent 5f29f21 commit 57a45d8

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

crates/go_to_line/src/cursor_position.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use editor::{Editor, ToPoint};
2-
use gpui::{AppContext, Subscription, Task, View, WeakView};
2+
use gpui::{AppContext, FocusHandle, FocusableView, Subscription, Task, View, WeakView};
33
use schemars::JsonSchema;
44
use serde::{Deserialize, Serialize};
55
use settings::{Settings, SettingsSources};
@@ -22,6 +22,7 @@ pub(crate) struct SelectionStats {
2222
pub struct CursorPosition {
2323
position: Option<Point>,
2424
selected_count: SelectionStats,
25+
context: Option<FocusHandle>,
2526
workspace: WeakView<Workspace>,
2627
update_position: Task<()>,
2728
_observe_active_editor: Option<Subscription>,
@@ -31,6 +32,7 @@ impl CursorPosition {
3132
pub fn new(workspace: &Workspace) -> Self {
3233
Self {
3334
position: None,
35+
context: None,
3436
selected_count: Default::default(),
3537
workspace: workspace.weak_handle(),
3638
update_position: Task::ready(()),
@@ -58,7 +60,8 @@ impl CursorPosition {
5860
match editor.mode() {
5961
editor::EditorMode::AutoHeight { .. }
6062
| editor::EditorMode::SingleLine { .. } => {
61-
cursor_position.position = None
63+
cursor_position.position = None;
64+
cursor_position.context = None;
6265
}
6366
editor::EditorMode::Full => {
6467
let mut last_selection = None::<Selection<usize>>;
@@ -87,6 +90,7 @@ impl CursorPosition {
8790
}
8891
cursor_position.position =
8992
last_selection.map(|s| s.head().to_point(&buffer));
93+
cursor_position.context = Some(editor.focus_handle(cx));
9094
}
9195
}
9296

@@ -158,6 +162,8 @@ impl Render for CursorPosition {
158162
);
159163
self.write_position(&mut text, cx);
160164

165+
let context = self.context.clone();
166+
161167
el.child(
162168
Button::new("go-to-line-column", text)
163169
.label_size(LabelSize::Small)
@@ -174,12 +180,18 @@ impl Render for CursorPosition {
174180
});
175181
}
176182
}))
177-
.tooltip(|cx| {
178-
Tooltip::for_action(
183+
.tooltip(move |cx| match context.as_ref() {
184+
Some(context) => Tooltip::for_action_in(
185+
"Go to Line/Column",
186+
&editor::actions::ToggleGoToLine,
187+
context,
188+
cx,
189+
),
190+
None => Tooltip::for_action(
179191
"Go to Line/Column",
180192
&editor::actions::ToggleGoToLine,
181193
cx,
182-
)
194+
),
183195
}),
184196
)
185197
})

0 commit comments

Comments
 (0)