summaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs32
1 files changed, 31 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 860d8e22..d198b803 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -3502,6 +3502,9 @@ fn right_bracket_mode(cx: &mut Context) {
})
}
+use helix_core::surround;
+use helix_core::textobject;
+
fn match_mode(cx: &mut Context) {
let count = cx.count;
cx.on_next_key(move |cx, event| {
@@ -3517,13 +3520,40 @@ fn match_mode(cx: &mut Context) {
's' => surround_add(cx),
'r' => surround_replace(cx),
'd' => surround_delete(cx),
+ 'a' => select_textobject(cx, textobject::TextObject::Around),
+ 'i' => select_textobject(cx, textobject::TextObject::Inside),
_ => (),
}
}
})
}
-use helix_core::surround;
+fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
+ let count = cx.count();
+ cx.on_next_key(move |cx, event| {
+ if let KeyEvent {
+ code: KeyCode::Char(ch),
+ ..
+ } = event
+ {
+ let (view, doc) = current!(cx.editor);
+ let text = doc.text().slice(..);
+
+ let selection = doc.selection(view.id).transform(|range| {
+ match ch {
+ 'w' => textobject::textobject_word(text, range, objtype, count),
+ // TODO: cancel new ranges if inconsistent surround matches across lines
+ ch if !ch.is_ascii_alphanumeric() => {
+ textobject::textobject_surround(text, range, objtype, ch, count)
+ }
+ _ => range,
+ }
+ });
+
+ doc.set_selection(view.id, selection);
+ }
+ })
+}
fn surround_add(cx: &mut Context) {
cx.on_next_key(move |cx, event| {