Skip to content

Commit

Permalink
Implement as a new command
Browse files Browse the repository at this point in the history
  • Loading branch information
Tudyx committed Jun 14, 2023
1 parent 9868b02 commit 7192f20
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ impl MappableCommand {
delete_selection, "Delete selection",
delete_selection_noyank, "Delete selection without yanking",
change_selection, "Change selection",
change_selection_with_indent, "Change selection and place the cursor at the appropriated indent",
change_selection_with_indent_noyank, "Change selection without yanking and place the cursor at the appropriated indent",
change_selection_noyank, "Change selection without yanking",
collapse_selection, "Collapse selection into single cursor",
flip_selections, "Flip selection cursor and anchor",
Expand Down Expand Up @@ -2313,6 +2315,7 @@ fn shrink_to_line_bounds(cx: &mut Context) {
enum Operation {
Delete,
Change,
ChangeWithIndent,
}

fn only_whole_lines(selection: &Selection, text: &Rope) -> bool {
Expand Down Expand Up @@ -2354,6 +2357,9 @@ fn delete_selection_impl(cx: &mut Context, op: Operation) {
exit_select_mode(cx);
}
Operation::Change => {
enter_insert_mode(cx);
}
Operation::ChangeWithIndent => {
if only_whole_lines {
open_above(cx);
} else {
Expand Down Expand Up @@ -2427,6 +2433,15 @@ fn change_selection_noyank(cx: &mut Context) {
delete_selection_impl(cx, Operation::Change);
}

fn change_selection_with_indent(cx: &mut Context) {
delete_selection_impl(cx, Operation::ChangeWithIndent);
}

fn change_selection_with_indent_noyank(cx: &mut Context) {
cx.register = Some('_');
delete_selection_impl(cx, Operation::ChangeWithIndent);
}

fn collapse_selection(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);
Expand Down

0 comments on commit 7192f20

Please sign in to comment.