vim: Add support for ctrl-g (#23562)
Co-Authored-By: Jon Walstedt <jon@walstedt.se> Closes #22094 Release Notes: - vim: Added support for ctrl-g Co-authored-by: Jon Walstedt <jon@walstedt.se>
This commit is contained in:
parent
f38d0ff069
commit
0ef53bf476
4 changed files with 62 additions and 11 deletions
|
@ -30,7 +30,7 @@ use editor::Bias;
|
|||
use editor::Editor;
|
||||
use editor::{display_map::ToDisplayPoint, movement};
|
||||
use gpui::{actions, ViewContext};
|
||||
use language::{Point, SelectionGoal};
|
||||
use language::{Point, SelectionGoal, ToPoint};
|
||||
use log::error;
|
||||
use multi_buffer::MultiBufferRow;
|
||||
|
||||
|
@ -56,6 +56,7 @@ actions!(
|
|||
ConvertToUpperCase,
|
||||
ConvertToLowerCase,
|
||||
ToggleComments,
|
||||
ShowLocation,
|
||||
Undo,
|
||||
Redo,
|
||||
]
|
||||
|
@ -75,6 +76,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
|
|||
Vim::action(editor, cx, Vim::yank_line);
|
||||
Vim::action(editor, cx, Vim::toggle_comments);
|
||||
Vim::action(editor, cx, Vim::paste);
|
||||
Vim::action(editor, cx, Vim::show_location);
|
||||
|
||||
Vim::action(editor, cx, |vim, _: &DeleteLeft, cx| {
|
||||
vim.record_current_action(cx);
|
||||
|
@ -419,6 +421,45 @@ impl Vim {
|
|||
self.yank_motion(motion::Motion::CurrentLine, count, cx)
|
||||
}
|
||||
|
||||
fn show_location(&mut self, _: &ShowLocation, cx: &mut ViewContext<Self>) {
|
||||
let count = Vim::take_count(cx);
|
||||
self.update_editor(cx, |vim, editor, cx| {
|
||||
let selection = editor.selections.newest_anchor();
|
||||
if let Some((_, buffer, _)) = editor.active_excerpt(cx) {
|
||||
let filename = if let Some(file) = buffer.read(cx).file() {
|
||||
if count.is_some() {
|
||||
if let Some(local) = file.as_local() {
|
||||
local.abs_path(cx).to_string_lossy().to_string()
|
||||
} else {
|
||||
file.full_path(cx).to_string_lossy().to_string()
|
||||
}
|
||||
} else {
|
||||
file.path().to_string_lossy().to_string()
|
||||
}
|
||||
} else {
|
||||
"[No Name]".into()
|
||||
};
|
||||
let buffer = buffer.read(cx);
|
||||
let snapshot = buffer.snapshot();
|
||||
let lines = buffer.max_point().row + 1;
|
||||
let current_line = selection.head().text_anchor.to_point(&snapshot).row;
|
||||
let percentage = current_line as f32 / lines as f32;
|
||||
let modified = if buffer.is_dirty() { " [modified]" } else { "" };
|
||||
vim.status_label = Some(
|
||||
format!(
|
||||
"{}{} {} lines --{:.0}%--",
|
||||
filename,
|
||||
modified,
|
||||
lines,
|
||||
percentage * 100.0,
|
||||
)
|
||||
.into(),
|
||||
);
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn toggle_comments(&mut self, _: &ToggleComments, cx: &mut ViewContext<Self>) {
|
||||
self.record_current_action(cx);
|
||||
self.store_visual_marks(cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue