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

Add dj & dl support - {n1}d{n2}{h | l} #80

Merged
merged 1 commit into from
Dec 1, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/src/state/notebook/inner_state/editing_normal_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,14 @@ async fn consume_delete(
state.inner_state = InnerState::EditingNormalMode(VimNormalState::Idle);
DeleteWordEnd(n).into()
}
Key(KeyEvent::H) => {
state.inner_state = InnerState::EditingNormalMode(VimNormalState::Idle);
DeleteCharsBack(n).into()
}
Key(KeyEvent::L) => {
state.inner_state = InnerState::EditingNormalMode(VimNormalState::Idle);
DeleteChars(n).into()
}
Key(KeyEvent::DollarSign) => {
state.inner_state = InnerState::EditingNormalMode(VimNormalState::Idle);

Expand Down Expand Up @@ -473,6 +481,14 @@ async fn consume_delete2(

DeleteInsideMode.into()
}
Key(KeyEvent::H) => {
state.inner_state = InnerState::EditingNormalMode(VimNormalState::Idle);
DeleteCharsBack(n1 * n2).into()
}
Key(KeyEvent::L) => {
state.inner_state = InnerState::EditingNormalMode(VimNormalState::Idle);
DeleteChars(n1 * n2).into()
}
Key(KeyEvent::Esc) => {
state.inner_state = InnerState::EditingNormalMode(VimNormalState::Idle);

Expand Down
1 change: 1 addition & 0 deletions core/src/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pub enum NormalModeTransition {
InsertNewLineBelow,
InsertNewLineAbove,
DeleteChars(usize),
DeleteCharsBack(usize),
DeleteLines(usize),
DeleteLinesAndInsert(usize),
DeleteWordEnd(usize),
Expand Down
26 changes: 20 additions & 6 deletions tui/src/transitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,7 @@ impl App {
}
MoveCursorBack(n) => {
let editor = self.context.notebook.get_editor_mut();
let (row, col) = editor.cursor();
let cursor_move = if col < n {
CursorMove::Head
} else {
CursorMove::Jump(row as u16, (col - n) as u16)
};
let cursor_move = cursor_move_back(editor, n);

editor.move_cursor(cursor_move);
}
Expand Down Expand Up @@ -340,6 +335,16 @@ impl App {
self.context.notebook.mark_dirty();
self.context.notebook.update_yank();
}
DeleteCharsBack(n) => {
let editor = self.context.notebook.get_editor_mut();
editor.start_selection();
let cursor_move = cursor_move_back(editor, n);

editor.move_cursor(cursor_move);
editor.cut();
self.context.notebook.mark_dirty();
self.context.notebook.update_yank();
}
Paste => {
let line_yanked = self.context.notebook.line_yanked;
let editor = self.context.notebook.get_editor_mut();
Expand Down Expand Up @@ -665,6 +670,15 @@ fn cursor_move_forward(editor: &TextArea, n: usize) -> CursorMove {
}
}

fn cursor_move_back(editor: &TextArea, n: usize) -> CursorMove {
let (row, col) = editor.cursor();
if col < n {
CursorMove::Head
} else {
CursorMove::Jump(row as u16, (col - n) as u16)
}
}

fn cursor_move_down(editor: &TextArea, n: usize) -> CursorMove {
let num_lines = editor.lines().len();
let (row, col) = editor.cursor();
Expand Down
4 changes: 4 additions & 0 deletions tui/src/views/dialog/vim_keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ pub fn draw(frame: &mut Frame, keymap_kind: VimKeymapKind) {
Line::raw("[b] Delete the word before the cursor."),
Line::raw("[0] Delete to the beginning of the line"),
Line::raw("[$] Delete to the end of the line, repeated by the specified number"),
Line::raw("[h] Delete the specified number of characters to the left"),
Line::raw("[l] Delete the specified number of characters to the right"),
]),
VimKeymapKind::NormalDelete2 => ("VIM NORMAL MODE KEYMAP - DELETE NUMBERING", vec![
Line::from("EXTENDING NUMBERING MODE".white().on_dark_gray()),
Expand All @@ -101,6 +103,8 @@ pub fn draw(frame: &mut Frame, keymap_kind: VimKeymapKind) {
Line::raw(""),
Line::from("DELETE TEXT".white().on_dark_gray()),
Line::raw("[d] Delete the specified number of lines"),
Line::raw("[h] Delete the specified number of characters to the left"),
Line::raw("[l] Delete the specified number of characters to the right"),
]),
VimKeymapKind::NormalChange => ("VIM NORMAL MODE KEYMAP - CHANGE", vec![
Line::from("TO CHANGE INSIDE MODE".white().on_dark_gray()),
Expand Down