Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add command and keybinds to delete line #2071

Merged
merged 1 commit into from Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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