Add a basic helix match operator
This commit is contained in:
parent
1f3575ad6e
commit
05bc741eaf
6 changed files with 51 additions and 7 deletions
|
@ -7,6 +7,7 @@ mod paste;
|
|||
pub(crate) mod repeat;
|
||||
mod scroll;
|
||||
pub(crate) mod search;
|
||||
mod select;
|
||||
pub mod substitute;
|
||||
mod toggle_comments;
|
||||
pub(crate) mod yank;
|
||||
|
@ -362,6 +363,7 @@ impl Vim {
|
|||
self.replace_with_register_object(object, around, window, cx)
|
||||
}
|
||||
Some(Operator::Exchange) => self.exchange_object(object, around, window, cx),
|
||||
Some(Operator::HelixMatch) => self.select_object(object, around, window, cx),
|
||||
_ => {
|
||||
// Can't do anything for namespace operators. Ignoring
|
||||
}
|
||||
|
|
29
crates/vim/src/normal/select.rs
Normal file
29
crates/vim/src/normal/select.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use text::SelectionGoal;
|
||||
use ui::{Context, Window};
|
||||
|
||||
use crate::{Vim, object::Object};
|
||||
|
||||
impl Vim {
|
||||
/// Selects the text object each cursor is over.
|
||||
pub fn select_object(
|
||||
&mut self,
|
||||
object: Object,
|
||||
around: bool,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.stop_recording(cx);
|
||||
self.update_editor(window, cx, |_, editor, window, cx| {
|
||||
editor.change_selections(Default::default(), window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let Some(range) = object.range(map, selection.clone(), around, None) else {
|
||||
return;
|
||||
};
|
||||
|
||||
selection.set_head(range.end, SelectionGoal::None);
|
||||
selection.start = range.start;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -399,11 +399,11 @@ impl Vim {
|
|||
let count = Self::take_count(cx);
|
||||
|
||||
match self.mode {
|
||||
Mode::Normal => self.normal_object(object, count, window, cx),
|
||||
Mode::Normal | Mode::HelixNormal => self.normal_object(object, count, window, cx),
|
||||
Mode::Visual | Mode::VisualLine | Mode::VisualBlock => {
|
||||
self.visual_object(object, count, window, cx)
|
||||
}
|
||||
Mode::Insert | Mode::Replace | Mode::HelixNormal => {
|
||||
Mode::Insert | Mode::Replace => {
|
||||
// Shouldn't execute a text object in insert mode. Ignoring
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,6 +132,7 @@ pub enum Operator {
|
|||
ToggleComments,
|
||||
ReplaceWithRegister,
|
||||
Exchange,
|
||||
HelixMatch,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
|
@ -1024,6 +1025,7 @@ impl Operator {
|
|||
Operator::RecordRegister => "q",
|
||||
Operator::ReplayRegister => "@",
|
||||
Operator::ToggleComments => "gc",
|
||||
Operator::HelixMatch => "ℳ",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1075,7 +1077,8 @@ impl Operator {
|
|||
| Operator::Object { .. }
|
||||
| Operator::ChangeSurrounds { target: None }
|
||||
| Operator::OppositeCase
|
||||
| Operator::ToggleComments => false,
|
||||
| Operator::ToggleComments
|
||||
| Operator::HelixMatch => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1114,7 +1117,8 @@ impl Operator {
|
|||
| Operator::Jump { .. }
|
||||
| Operator::Register
|
||||
| Operator::RecordRegister
|
||||
| Operator::ReplayRegister => false,
|
||||
| Operator::ReplayRegister
|
||||
| Operator::HelixMatch => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -222,6 +222,8 @@ actions!(
|
|||
PushReplaceWithRegister,
|
||||
/// Toggles comments.
|
||||
PushToggleComments,
|
||||
/// Starts a match operation.
|
||||
PushHelixMatch,
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -761,6 +763,9 @@ impl Vim {
|
|||
Vim::action(editor, cx, |vim, _: &Enter, window, cx| {
|
||||
vim.input_ignored("\n".into(), window, cx)
|
||||
});
|
||||
Vim::action(editor, cx, |vim, _: &PushHelixMatch, window, cx| {
|
||||
vim.push_operator(Operator::HelixMatch, window, cx)
|
||||
});
|
||||
|
||||
normal::register(editor, cx);
|
||||
insert::register(editor, cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue