Skip to content

Commit

Permalink
feat: add command and keybinds to delete line
Browse files Browse the repository at this point in the history
  • Loading branch information
panekj committed Jan 28, 2023
1 parent 0ae86e6 commit c8bb960
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -23,6 +23,7 @@
- [#2004](https://github.com/lapce/lapce/pull/2004): Add ToggleHistory command
- [#2033](https://github.com/lapce/lapce/pull/2033): Add setting for double click delay (Currently only works for opening file from the explorer)
- [#2045](https://github.com/lapce/lapce/pull/2045): Add 'Rename Symbol' option on right-click
- [#2071](https://github.com/lapce/lapce/pull/2071): Add command and keybinds to delete line

### Bug Fixes
- [#1911](https://github.com/lapce/lapce/pull/1911): Fix movement on selections with left/right arrow keys
Expand Down
5 changes: 5 additions & 0 deletions defaults/keymaps-macos.toml
Expand Up @@ -81,6 +81,11 @@ key = "meta+right"
command = "line_end"
mode = "i"

[[keymaps]]
key = "meta+shift+k"
command = "delete_line"
mode = "i"

[[keymaps]]
key = "alt+backspace"
command = "delete_word_backward"
Expand Down
5 changes: 5 additions & 0 deletions defaults/keymaps-nonmacos.toml
Expand Up @@ -111,6 +111,11 @@ key = "ctrl+delete"
command = "delete_word_forward"
mode = "i"

[[keymaps]]
key = "shift+delete"
command = "delete_line"
mode = "i"

[[keymaps]]
key = "ctrl+|"
command = "match_pairs"
Expand Down
2 changes: 2 additions & 0 deletions lapce-core/src/command.rs
Expand Up @@ -30,6 +30,8 @@ pub enum EditCommand {
DeleteBackward,
#[strum(serialize = "delete_forward")]
DeleteForward,
#[strum(serialize = "delete_line")]
DeleteLine,
#[strum(serialize = "delete_forward_and_insert")]
DeleteForwardAndInsert,
#[strum(serialize = "delete_word_and_insert")]
Expand Down
17 changes: 17 additions & 0 deletions lapce-core/src/editor.rs
Expand Up @@ -1225,6 +1225,23 @@ impl Editor {
cursor.update_selection(buffer, selection);
vec![(delta, inval_lines, edits)]
}
DeleteLine => {
let selection = cursor.edit_selection(buffer);
let (start, end) = format_start_end(
buffer,
selection.min_offset(),
selection.max_offset(),
true,
true,
);
let selection = Selection::region(start, end);
let (delta, inval_lines, edits) =
buffer.edit(&[(&selection, "")], EditType::Delete);
let selection =
selection.apply_delta(&delta, true, InsertDrift::Default);
cursor.mode = CursorMode::Insert(selection);
vec![(delta, inval_lines, edits)]
}
DeleteWordForward => {
let selection = match cursor.mode {
CursorMode::Normal(_) | CursorMode::Visual { .. } => {
Expand Down

0 comments on commit c8bb960

Please sign in to comment.