|
|
@ -523,6 +523,10 @@ impl MappableCommand {
|
|
|
|
surround_delete, "Surround delete",
|
|
|
|
surround_delete, "Surround delete",
|
|
|
|
select_textobject_around, "Select around object",
|
|
|
|
select_textobject_around, "Select around object",
|
|
|
|
select_textobject_inner, "Select inside object",
|
|
|
|
select_textobject_inner, "Select inside object",
|
|
|
|
|
|
|
|
select_next_word, "Select next whole word",
|
|
|
|
|
|
|
|
select_next_long_word, "Select next whole long word",
|
|
|
|
|
|
|
|
select_prev_word, "Select previous whole word",
|
|
|
|
|
|
|
|
select_prev_long_word, "Select previous whole long word",
|
|
|
|
goto_next_function, "Goto next function",
|
|
|
|
goto_next_function, "Goto next function",
|
|
|
|
goto_prev_function, "Goto previous function",
|
|
|
|
goto_prev_function, "Goto previous function",
|
|
|
|
goto_next_class, "Goto next type definition",
|
|
|
|
goto_next_class, "Goto next type definition",
|
|
|
@ -5454,6 +5458,39 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
|
|
|
|
cx.on_next_key(move |cx, event| {
|
|
|
|
cx.on_next_key(move |cx, event| {
|
|
|
|
cx.editor.autoinfo = None;
|
|
|
|
cx.editor.autoinfo = None;
|
|
|
|
if let Some(ch) = event.char() {
|
|
|
|
if let Some(ch) = event.char() {
|
|
|
|
|
|
|
|
select_textobject_for_char(cx, ch, objtype, count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let title = match objtype {
|
|
|
|
|
|
|
|
textobject::TextObject::Inside => "Match inside",
|
|
|
|
|
|
|
|
textobject::TextObject::Around => "Match around",
|
|
|
|
|
|
|
|
_ => return,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
let help_text = [
|
|
|
|
|
|
|
|
("w", "Word"),
|
|
|
|
|
|
|
|
("W", "WORD"),
|
|
|
|
|
|
|
|
("p", "Paragraph"),
|
|
|
|
|
|
|
|
("t", "Type definition (tree-sitter)"),
|
|
|
|
|
|
|
|
("f", "Function (tree-sitter)"),
|
|
|
|
|
|
|
|
("a", "Argument/parameter (tree-sitter)"),
|
|
|
|
|
|
|
|
("c", "Comment (tree-sitter)"),
|
|
|
|
|
|
|
|
("T", "Test (tree-sitter)"),
|
|
|
|
|
|
|
|
("e", "Data structure entry (tree-sitter)"),
|
|
|
|
|
|
|
|
("m", "Closest surrounding pair (tree-sitter)"),
|
|
|
|
|
|
|
|
("g", "Change"),
|
|
|
|
|
|
|
|
(" ", "... or any character acting as a pair"),
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cx.editor.autoinfo = Some(Info::new(title, &help_text));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn select_textobject_for_char(
|
|
|
|
|
|
|
|
cx: &mut Context,
|
|
|
|
|
|
|
|
ch: char,
|
|
|
|
|
|
|
|
objtype: textobject::TextObject,
|
|
|
|
|
|
|
|
count: usize,
|
|
|
|
|
|
|
|
) {
|
|
|
|
let textobject = move |editor: &mut Editor| {
|
|
|
|
let textobject = move |editor: &mut Editor| {
|
|
|
|
let (view, doc) = current!(editor);
|
|
|
|
let (view, doc) = current!(editor);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
|
let text = doc.text().slice(..);
|
|
|
@ -5530,29 +5567,54 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
cx.editor.apply_motion(textobject);
|
|
|
|
cx.editor.apply_motion(textobject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let title = match objtype {
|
|
|
|
fn select_next_word(cx: &mut Context) {
|
|
|
|
textobject::TextObject::Inside => "Match inside",
|
|
|
|
let current_selection = get_current_selection(cx);
|
|
|
|
textobject::TextObject::Around => "Match around",
|
|
|
|
select_textobject_for_char(cx, 'w', textobject::TextObject::Inside, cx.count());
|
|
|
|
_ => return,
|
|
|
|
let new_selection = get_current_selection(cx);
|
|
|
|
};
|
|
|
|
if current_selection.visual_eq(new_selection) {
|
|
|
|
let help_text = [
|
|
|
|
move_next_word_end(cx);
|
|
|
|
("w", "Word"),
|
|
|
|
select_textobject_for_char(cx, 'w', textobject::TextObject::Inside, cx.count());
|
|
|
|
("W", "WORD"),
|
|
|
|
}
|
|
|
|
("p", "Paragraph"),
|
|
|
|
}
|
|
|
|
("t", "Type definition (tree-sitter)"),
|
|
|
|
|
|
|
|
("f", "Function (tree-sitter)"),
|
|
|
|
|
|
|
|
("a", "Argument/parameter (tree-sitter)"),
|
|
|
|
|
|
|
|
("c", "Comment (tree-sitter)"),
|
|
|
|
|
|
|
|
("T", "Test (tree-sitter)"),
|
|
|
|
|
|
|
|
("e", "Data structure entry (tree-sitter)"),
|
|
|
|
|
|
|
|
("m", "Closest surrounding pair (tree-sitter)"),
|
|
|
|
|
|
|
|
("g", "Change"),
|
|
|
|
|
|
|
|
(" ", "... or any character acting as a pair"),
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cx.editor.autoinfo = Some(Info::new(title, &help_text));
|
|
|
|
fn select_next_long_word(cx: &mut Context) {
|
|
|
|
|
|
|
|
let current_selection = get_current_selection(cx);
|
|
|
|
|
|
|
|
select_textobject_for_char(cx, 'W', textobject::TextObject::Inside, cx.count());
|
|
|
|
|
|
|
|
let new_selection = get_current_selection(cx);
|
|
|
|
|
|
|
|
if current_selection.visual_eq(new_selection) {
|
|
|
|
|
|
|
|
move_next_long_word_end(cx);
|
|
|
|
|
|
|
|
select_textobject_for_char(cx, 'W', textobject::TextObject::Inside, cx.count());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn select_prev_word(cx: &mut Context) {
|
|
|
|
|
|
|
|
let current_selection = get_current_selection(cx);
|
|
|
|
|
|
|
|
select_textobject_for_char(cx, 'w', textobject::TextObject::Inside, cx.count());
|
|
|
|
|
|
|
|
flip_selections(cx);
|
|
|
|
|
|
|
|
let new_selection = get_current_selection(cx);
|
|
|
|
|
|
|
|
if current_selection.visual_eq(new_selection) {
|
|
|
|
|
|
|
|
move_prev_word_start(cx);
|
|
|
|
|
|
|
|
select_textobject_for_char(cx, 'w', textobject::TextObject::Inside, cx.count());
|
|
|
|
|
|
|
|
flip_selections(cx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn select_prev_long_word(cx: &mut Context) {
|
|
|
|
|
|
|
|
let current_selection = get_current_selection(cx);
|
|
|
|
|
|
|
|
select_textobject_for_char(cx, 'W', textobject::TextObject::Inside, cx.count());
|
|
|
|
|
|
|
|
flip_selections(cx);
|
|
|
|
|
|
|
|
let new_selection = get_current_selection(cx);
|
|
|
|
|
|
|
|
if current_selection.visual_eq(new_selection) {
|
|
|
|
|
|
|
|
move_prev_long_word_start(cx);
|
|
|
|
|
|
|
|
select_textobject_for_char(cx, 'W', textobject::TextObject::Inside, cx.count());
|
|
|
|
|
|
|
|
flip_selections(cx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn get_current_selection(cx: &mut Context) -> Selection {
|
|
|
|
|
|
|
|
let (view, doc) = current!(cx.editor);
|
|
|
|
|
|
|
|
doc.selection(view.id).clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn surround_add(cx: &mut Context) {
|
|
|
|
fn surround_add(cx: &mut Context) {
|
|
|
|