Add a keybinding to the Go to Line button (#21350)
Release Notes: - N/A
This commit is contained in:
parent
5f29f214c3
commit
57a45d80ad
1 changed files with 17 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
||||||
use editor::{Editor, ToPoint};
|
use editor::{Editor, ToPoint};
|
||||||
use gpui::{AppContext, Subscription, Task, View, WeakView};
|
use gpui::{AppContext, FocusHandle, FocusableView, Subscription, Task, View, WeakView};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use settings::{Settings, SettingsSources};
|
use settings::{Settings, SettingsSources};
|
||||||
|
@ -22,6 +22,7 @@ pub(crate) struct SelectionStats {
|
||||||
pub struct CursorPosition {
|
pub struct CursorPosition {
|
||||||
position: Option<Point>,
|
position: Option<Point>,
|
||||||
selected_count: SelectionStats,
|
selected_count: SelectionStats,
|
||||||
|
context: Option<FocusHandle>,
|
||||||
workspace: WeakView<Workspace>,
|
workspace: WeakView<Workspace>,
|
||||||
update_position: Task<()>,
|
update_position: Task<()>,
|
||||||
_observe_active_editor: Option<Subscription>,
|
_observe_active_editor: Option<Subscription>,
|
||||||
|
@ -31,6 +32,7 @@ impl CursorPosition {
|
||||||
pub fn new(workspace: &Workspace) -> Self {
|
pub fn new(workspace: &Workspace) -> Self {
|
||||||
Self {
|
Self {
|
||||||
position: None,
|
position: None,
|
||||||
|
context: None,
|
||||||
selected_count: Default::default(),
|
selected_count: Default::default(),
|
||||||
workspace: workspace.weak_handle(),
|
workspace: workspace.weak_handle(),
|
||||||
update_position: Task::ready(()),
|
update_position: Task::ready(()),
|
||||||
|
@ -58,7 +60,8 @@ impl CursorPosition {
|
||||||
match editor.mode() {
|
match editor.mode() {
|
||||||
editor::EditorMode::AutoHeight { .. }
|
editor::EditorMode::AutoHeight { .. }
|
||||||
| editor::EditorMode::SingleLine { .. } => {
|
| editor::EditorMode::SingleLine { .. } => {
|
||||||
cursor_position.position = None
|
cursor_position.position = None;
|
||||||
|
cursor_position.context = None;
|
||||||
}
|
}
|
||||||
editor::EditorMode::Full => {
|
editor::EditorMode::Full => {
|
||||||
let mut last_selection = None::<Selection<usize>>;
|
let mut last_selection = None::<Selection<usize>>;
|
||||||
|
@ -87,6 +90,7 @@ impl CursorPosition {
|
||||||
}
|
}
|
||||||
cursor_position.position =
|
cursor_position.position =
|
||||||
last_selection.map(|s| s.head().to_point(&buffer));
|
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);
|
self.write_position(&mut text, cx);
|
||||||
|
|
||||||
|
let context = self.context.clone();
|
||||||
|
|
||||||
el.child(
|
el.child(
|
||||||
Button::new("go-to-line-column", text)
|
Button::new("go-to-line-column", text)
|
||||||
.label_size(LabelSize::Small)
|
.label_size(LabelSize::Small)
|
||||||
|
@ -174,12 +180,18 @@ impl Render for CursorPosition {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.tooltip(|cx| {
|
.tooltip(move |cx| match context.as_ref() {
|
||||||
Tooltip::for_action(
|
Some(context) => Tooltip::for_action_in(
|
||||||
|
"Go to Line/Column",
|
||||||
|
&editor::actions::ToggleGoToLine,
|
||||||
|
context,
|
||||||
|
cx,
|
||||||
|
),
|
||||||
|
None => Tooltip::for_action(
|
||||||
"Go to Line/Column",
|
"Go to Line/Column",
|
||||||
&editor::actions::ToggleGoToLine,
|
&editor::actions::ToggleGoToLine,
|
||||||
cx,
|
cx,
|
||||||
)
|
),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue