mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 09:26:19 +04:00
add append_character_interactive
command
this behaves like regular append with respect to selections: the newly inserted text will be selected when the command finishes, unlike when using `insert_char_interactive`.
This commit is contained in:
parent
08ec9d5ada
commit
77699f1473
@ -398,6 +398,7 @@ pub fn doc(&self) -> &str {
|
||||
insert_tab, "Insert tab char",
|
||||
insert_newline, "Insert newline char",
|
||||
insert_char_interactive, "Insert an interactively-chosen char",
|
||||
append_char_interactive, "Append an interactively-chosen char",
|
||||
delete_char_backward, "Delete previous char",
|
||||
delete_char_forward, "Delete next char",
|
||||
delete_word_backward, "Delete previous word",
|
||||
@ -3820,7 +3821,20 @@ fn insert_tab_impl(cx: &mut Context, count: usize) {
|
||||
doc.apply(&transaction, view.id);
|
||||
}
|
||||
|
||||
pub fn append_char_interactive(cx: &mut Context) {
|
||||
// Save the current mode, so we can restore it later.
|
||||
let mode = cx.editor.mode;
|
||||
append_mode(cx);
|
||||
insert_selection_interactive(cx, mode);
|
||||
}
|
||||
|
||||
pub fn insert_char_interactive(cx: &mut Context) {
|
||||
let mode = cx.editor.mode;
|
||||
insert_mode(cx);
|
||||
insert_selection_interactive(cx, mode);
|
||||
}
|
||||
|
||||
fn insert_selection_interactive(cx: &mut Context, old_mode: Mode) {
|
||||
let count = cx.count();
|
||||
|
||||
// need to wait for next key
|
||||
@ -3845,6 +3859,8 @@ pub fn insert_char_interactive(cx: &mut Context) {
|
||||
key!(Tab) => insert_tab_impl(cx, count),
|
||||
_ => (),
|
||||
};
|
||||
// Restore the old mode.
|
||||
cx.editor.mode = old_mode;
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user