mirror of https://github.com/helix-editor/helix
Implement no-yank delete/change (#1099)
parent
57c14d4a93
commit
72f606ee19
|
@ -45,44 +45,46 @@
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
| Key | Description | Command |
|
| Key | Description | Command |
|
||||||
| ----- | ----------- | ------- |
|
| ----- | ----------- | ------- |
|
||||||
| `r` | Replace with a character | `replace` |
|
| `r` | Replace with a character | `replace` |
|
||||||
| `R` | Replace with yanked text | `replace_with_yanked` |
|
| `R` | Replace with yanked text | `replace_with_yanked` |
|
||||||
| `~` | Switch case of the selected text | `switch_case` |
|
| `~` | Switch case of the selected text | `switch_case` |
|
||||||
| `` ` `` | Set the selected text to lower case | `switch_to_lowercase` |
|
| `` ` `` | Set the selected text to lower case | `switch_to_lowercase` |
|
||||||
| `` Alt-` `` | Set the selected text to upper case | `switch_to_uppercase` |
|
| `` Alt-` `` | Set the selected text to upper case | `switch_to_uppercase` |
|
||||||
| `i` | Insert before selection | `insert_mode` |
|
| `i` | Insert before selection | `insert_mode` |
|
||||||
| `a` | Insert after selection (append) | `append_mode` |
|
| `a` | Insert after selection (append) | `append_mode` |
|
||||||
| `I` | Insert at the start of the line | `prepend_to_line` |
|
| `I` | Insert at the start of the line | `prepend_to_line` |
|
||||||
| `A` | Insert at the end of the line | `append_to_line` |
|
| `A` | Insert at the end of the line | `append_to_line` |
|
||||||
| `o` | Open new line below selection | `open_below` |
|
| `o` | Open new line below selection | `open_below` |
|
||||||
| `O` | Open new line above selection | `open_above` |
|
| `O` | Open new line above selection | `open_above` |
|
||||||
| `.` | Repeat last change | N/A |
|
| `.` | Repeat last change | N/A |
|
||||||
| `u` | Undo change | `undo` |
|
| `u` | Undo change | `undo` |
|
||||||
| `U` | Redo change | `redo` |
|
| `U` | Redo change | `redo` |
|
||||||
| `Alt-u` | Move backward in history | `earlier` |
|
| `Alt-u` | Move backward in history | `earlier` |
|
||||||
| `Alt-U` | Move forward in history | `later` |
|
| `Alt-U` | Move forward in history | `later` |
|
||||||
| `y` | Yank selection | `yank` |
|
| `y` | Yank selection | `yank` |
|
||||||
| `p` | Paste after selection | `paste_after` |
|
| `p` | Paste after selection | `paste_after` |
|
||||||
| `P` | Paste before selection | `paste_before` |
|
| `P` | Paste before selection | `paste_before` |
|
||||||
| `"` `<reg>` | Select a register to yank to or paste from | `select_register` |
|
| `"` `<reg>` | Select a register to yank to or paste from | `select_register` |
|
||||||
| `>` | Indent selection | `indent` |
|
| `>` | Indent selection | `indent` |
|
||||||
| `<` | Unindent selection | `unindent` |
|
| `<` | Unindent selection | `unindent` |
|
||||||
| `=` | Format selection (**LSP**) | `format_selections` |
|
| `=` | Format selection (**LSP**) | `format_selections` |
|
||||||
| `d` | Delete selection | `delete_selection` |
|
| `d` | Delete selection | `delete_selection` |
|
||||||
| `c` | Change selection (delete and enter insert mode) | `change_selection` |
|
| `Alt-d` | Delete selection, without yanking | `delete_selection_noyank` |
|
||||||
| `Ctrl-a` | Increment object (number) under cursor | `increment` |
|
| `c` | Change selection (delete and enter insert mode) | `change_selection` |
|
||||||
| `Ctrl-x` | Decrement object (number) under cursor | `decrement` |
|
| `Alt-c` | Change selection (delete and enter insert mode, without yanking) | `change_selection_noyank` |
|
||||||
|
| `Ctrl-a` | Increment object (number) under cursor | `increment` |
|
||||||
|
| `Ctrl-x` | Decrement object (number) under cursor | `decrement` |
|
||||||
|
|
||||||
#### Shell
|
#### Shell
|
||||||
|
|
||||||
| Key | Description | Command |
|
| Key | Description | Command |
|
||||||
| ------ | ----------- | ------- |
|
| ------ | ----------- | ------- |
|
||||||
| <code>|</code> | Pipe each selection through shell command, replacing with output | `shell_pipe` |
|
| <code>|</code> | Pipe each selection through shell command, replacing with output | `shell_pipe` |
|
||||||
| <code>A-|</code> | Pipe each selection into shell command, ignoring output | `shell_pipe_to` |
|
| <code>Alt-|</code> | Pipe each selection into shell command, ignoring output | `shell_pipe_to` |
|
||||||
| `!` | Run shell command, inserting output before each selection | `shell_insert_output` |
|
| `!` | Run shell command, inserting output before each selection | `shell_insert_output` |
|
||||||
| `A-!` | Run shell command, appending output after each selection | `shell_append_output` |
|
| `Alt-!` | Run shell command, appending output after each selection | `shell_append_output` |
|
||||||
|
|
||||||
|
|
||||||
### Selection manipulation
|
### Selection manipulation
|
||||||
|
|
|
@ -9,7 +9,6 @@ use helix_core::{
|
||||||
numbers::NumberIncrementor,
|
numbers::NumberIncrementor,
|
||||||
object, pos_at_coords,
|
object, pos_at_coords,
|
||||||
regex::{self, Regex, RegexBuilder},
|
regex::{self, Regex, RegexBuilder},
|
||||||
register::Register,
|
|
||||||
search, selection, surround, textobject,
|
search, selection, surround, textobject,
|
||||||
unicode::width::UnicodeWidthChar,
|
unicode::width::UnicodeWidthChar,
|
||||||
LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice, Selection, SmallVec, Tendril,
|
LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice, Selection, SmallVec, Tendril,
|
||||||
|
@ -232,7 +231,9 @@ impl Command {
|
||||||
extend_line, "Select current line, if already selected, extend to next line",
|
extend_line, "Select current line, if already selected, extend to next line",
|
||||||
extend_to_line_bounds, "Extend selection to line bounds (line-wise selection)",
|
extend_to_line_bounds, "Extend selection to line bounds (line-wise selection)",
|
||||||
delete_selection, "Delete selection",
|
delete_selection, "Delete selection",
|
||||||
|
delete_selection_noyank, "Delete selection, without yanking",
|
||||||
change_selection, "Change selection (delete and enter insert mode)",
|
change_selection, "Change selection (delete and enter insert mode)",
|
||||||
|
change_selection_noyank, "Change selection (delete and enter insert mode, without yanking)",
|
||||||
collapse_selection, "Collapse selection onto a single cursor",
|
collapse_selection, "Collapse selection onto a single cursor",
|
||||||
flip_selections, "Flip selection cursor and anchor",
|
flip_selections, "Flip selection cursor and anchor",
|
||||||
insert_mode, "Insert before selection",
|
insert_mode, "Insert before selection",
|
||||||
|
@ -1693,19 +1694,42 @@ fn extend_to_line_bounds(cx: &mut Context) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete_selection_impl(reg: &mut Register, doc: &mut Document, view_id: ViewId) {
|
enum Operation {
|
||||||
let text = doc.text().slice(..);
|
Delete,
|
||||||
let selection = doc.selection(view_id);
|
Change,
|
||||||
|
}
|
||||||
|
|
||||||
// first yank the selection
|
fn delete_selection_impl(cx: &mut Context, op: Operation) {
|
||||||
let values: Vec<String> = selection.fragments(text).map(Cow::into_owned).collect();
|
let (view, doc) = current!(cx.editor);
|
||||||
reg.write(values);
|
|
||||||
|
let text = doc.text().slice(..);
|
||||||
|
let selection = doc.selection(view.id);
|
||||||
|
|
||||||
|
if cx.register != Some('_') {
|
||||||
|
// first yank the selection
|
||||||
|
let values: Vec<String> = selection.fragments(text).map(Cow::into_owned).collect();
|
||||||
|
let reg_name = cx.register.unwrap_or('"');
|
||||||
|
let registers = &mut cx.editor.registers;
|
||||||
|
let reg = registers.get_mut(reg_name);
|
||||||
|
reg.write(values);
|
||||||
|
};
|
||||||
|
|
||||||
// then delete
|
// then delete
|
||||||
let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
|
let transaction = Transaction::change_by_selection(doc.text(), selection, |range| {
|
||||||
(range.from(), range.to(), None)
|
(range.from(), range.to(), None)
|
||||||
});
|
});
|
||||||
doc.apply(&transaction, view_id);
|
doc.apply(&transaction, view.id);
|
||||||
|
|
||||||
|
match op {
|
||||||
|
Operation::Delete => {
|
||||||
|
doc.append_changes_to_history(view.id);
|
||||||
|
// exit select mode, if currently in select mode
|
||||||
|
exit_select_mode(cx);
|
||||||
|
}
|
||||||
|
Operation::Change => {
|
||||||
|
enter_insert_mode(doc);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1720,25 +1744,21 @@ fn delete_selection_insert_mode(doc: &mut Document, view: &View, selection: &Sel
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete_selection(cx: &mut Context) {
|
fn delete_selection(cx: &mut Context) {
|
||||||
let reg_name = cx.register.unwrap_or('"');
|
delete_selection_impl(cx, Operation::Delete);
|
||||||
let (view, doc) = current!(cx.editor);
|
}
|
||||||
let registers = &mut cx.editor.registers;
|
|
||||||
let reg = registers.get_mut(reg_name);
|
|
||||||
delete_selection_impl(reg, doc, view.id);
|
|
||||||
|
|
||||||
doc.append_changes_to_history(view.id);
|
fn delete_selection_noyank(cx: &mut Context) {
|
||||||
|
cx.register = Some('_');
|
||||||
// exit select mode, if currently in select mode
|
delete_selection_impl(cx, Operation::Delete);
|
||||||
exit_select_mode(cx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_selection(cx: &mut Context) {
|
fn change_selection(cx: &mut Context) {
|
||||||
let reg_name = cx.register.unwrap_or('"');
|
delete_selection_impl(cx, Operation::Change);
|
||||||
let (view, doc) = current!(cx.editor);
|
}
|
||||||
let registers = &mut cx.editor.registers;
|
|
||||||
let reg = registers.get_mut(reg_name);
|
fn change_selection_noyank(cx: &mut Context) {
|
||||||
delete_selection_impl(reg, doc, view.id);
|
cx.register = Some('_');
|
||||||
enter_insert_mode(doc);
|
delete_selection_impl(cx, Operation::Change);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collapse_selection(cx: &mut Context) {
|
fn collapse_selection(cx: &mut Context) {
|
||||||
|
|
|
@ -537,9 +537,9 @@ impl Default for Keymaps {
|
||||||
"O" => open_above,
|
"O" => open_above,
|
||||||
|
|
||||||
"d" => delete_selection,
|
"d" => delete_selection,
|
||||||
// TODO: also delete without yanking
|
"A-d" => delete_selection_noyank,
|
||||||
"c" => change_selection,
|
"c" => change_selection,
|
||||||
// TODO: also change delete without yanking
|
"A-c" => change_selection_noyank,
|
||||||
|
|
||||||
"C" => copy_selection_on_next_line,
|
"C" => copy_selection_on_next_line,
|
||||||
"A-C" => copy_selection_on_prev_line,
|
"A-C" => copy_selection_on_prev_line,
|
||||||
|
|
Loading…
Reference in New Issue