working quote and bracket text objects

This commit is contained in:
K Simmons 2022-10-11 15:17:29 -07:00
parent 0d31ea7cf2
commit 673041d1f5
7 changed files with 237 additions and 37 deletions

View file

@ -1,5 +1,5 @@
use crate::{motion::Motion, object::Object, state::Mode, utils::copy_selections_content, Vim};
use editor::{char_kind, display_map::DisplaySnapshot, movement, Autoscroll, DisplayPoint};
use editor::{char_kind, display_map::DisplaySnapshot, movement, Autoscroll, Bias, DisplayPoint};
use gpui::MutableAppContext;
use language::Selection;
@ -25,20 +25,28 @@ pub fn change_motion(vim: &mut Vim, motion: Motion, times: usize, cx: &mut Mutab
}
pub fn change_object(vim: &mut Vim, object: Object, around: bool, cx: &mut MutableAppContext) {
let mut objects_found = false;
vim.update_active_editor(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);
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);
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
s.move_with(|map, selection| {
object.expand_selection(map, selection, around);
objects_found |= object.expand_selection(map, selection, around);
});
});
copy_selections_content(editor, false, cx);
editor.insert("", cx);
if objects_found {
copy_selections_content(editor, false, cx);
editor.insert("", cx);
}
});
});
vim.switch_mode(Mode::Insert, false, cx);
if objects_found {
vim.switch_mode(Mode::Insert, false, cx);
} else {
vim.switch_mode(Mode::Normal, false, cx);
}
}
// From the docs https://vimhelp.org/change.txt.html#cw

View file

@ -51,7 +51,7 @@ pub fn delete_object(vim: &mut Vim, object: Object, around: bool, cx: &mut Mutab
.chars_at(selection.start)
.take_while(|(_, p)| p < &selection.end)
.all(|(char, _)| char == '\n')
|| offset_range.is_empty();
&& !offset_range.is_empty();
let end_at_newline = map
.chars_at(selection.end)
.next()