Enable copy and paste in vim mode
This commit is contained in:
parent
d094d1d891
commit
082036161f
10 changed files with 183 additions and 34 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::{motion::Motion, state::Mode, Vim};
|
||||
use editor::{char_kind, movement, Autoscroll, ClipboardSelection};
|
||||
use gpui::{impl_actions, ClipboardItem, MutableAppContext, ViewContext};
|
||||
use crate::{motion::Motion, state::Mode, utils::copy_selections_content, Vim};
|
||||
use editor::{char_kind, movement, Autoscroll};
|
||||
use gpui::{impl_actions, MutableAppContext, ViewContext};
|
||||
use serde::Deserialize;
|
||||
use workspace::Workspace;
|
||||
|
||||
|
@ -22,26 +22,13 @@ pub fn change_over(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
|
|||
editor.transact(cx, |editor, cx| {
|
||||
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
|
||||
editor.set_clip_at_line_ends(false, cx);
|
||||
let mut text = String::new();
|
||||
let buffer = editor.buffer().read(cx).snapshot(cx);
|
||||
let mut clipboard_selections = Vec::with_capacity(editor.selections.count());
|
||||
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
motion.expand_selection(map, selection, false);
|
||||
let mut len = 0;
|
||||
let range = selection.start.to_point(map)..selection.end.to_point(map);
|
||||
for chunk in buffer.text_for_range(range) {
|
||||
text.push_str(chunk);
|
||||
len += chunk.len();
|
||||
}
|
||||
clipboard_selections.push(ClipboardSelection {
|
||||
len,
|
||||
is_entire_line: motion.linewise(),
|
||||
});
|
||||
});
|
||||
});
|
||||
copy_selections_content(editor, motion.linewise(), cx);
|
||||
editor.insert(&"", cx);
|
||||
cx.write_to_clipboard(ClipboardItem::new(text).with_metadata(clipboard_selections));
|
||||
});
|
||||
});
|
||||
vim.switch_mode(Mode::Insert, cx)
|
||||
|
@ -79,6 +66,7 @@ fn change_word(
|
|||
});
|
||||
});
|
||||
});
|
||||
copy_selections_content(editor, false, cx);
|
||||
editor.insert(&"", cx);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{motion::Motion, Vim};
|
||||
use crate::{motion::Motion, utils::copy_selections_content, Vim};
|
||||
use collections::HashMap;
|
||||
use editor::{Autoscroll, Bias};
|
||||
use gpui::MutableAppContext;
|
||||
|
@ -15,6 +15,7 @@ pub fn delete_over(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
|
|||
original_columns.insert(selection.id, original_head.column());
|
||||
});
|
||||
});
|
||||
copy_selections_content(editor, motion.linewise(), cx);
|
||||
editor.insert(&"", cx);
|
||||
|
||||
// Fixup cursor position after the deletion
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue