From 1e2d0625343baae205cd7ec9675f0ce75975f3a3 Mon Sep 17 00:00:00 2001 From: Kyohei Uto Date: Sat, 9 Dec 2023 05:59:39 +0900 Subject: Add ctrl-h for backspace functionality for command line --- src/run.rs | 73 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/src/run.rs b/src/run.rs index 1b5ee73..24fb2ad 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1942,26 +1942,25 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> { .. }) = event::read()? { - // to put the item name(s) in register - if modifiers == KeyModifiers::CONTROL - && code == KeyCode::Char('r') - { - if let Event::Key(KeyEvent { - code, - kind: KeyEventKind::Press, - .. - }) = event::read()? - { - if let Some(reg) = state.registers.check_reg(&code) + match (code, modifiers) { + (KeyCode::Char('r'), KeyModifiers::CONTROL) => { + if let Event::Key(KeyEvent { + code, + kind: KeyEventKind::Press, + .. + }) = event::read()? { - if !reg.is_empty() { - let to_be_inserted = reg - .iter() - .map(|x| x.file_name.clone()) - .collect::>() - .join(" "); - for c in to_be_inserted.chars() { - if let Some(to_be_added) = + if let Some(reg) = + state.registers.check_reg(&code) + { + if !reg.is_empty() { + let to_be_inserted = reg + .iter() + .map(|x| x.file_name.clone()) + .collect::>() + .join(" "); + for c in to_be_inserted.chars() { + if let Some(to_be_added) = unicode_width::UnicodeWidthChar::width(c) { if current_pos + to_be_added as u16 @@ -1973,33 +1972,32 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> { current_char_pos += 1; current_pos += to_be_added as u16; } + } + go_to_info_line_and_reset(); + print!( + ":{}", + &command.iter().collect::(), + ); + move_to(current_pos, 2); + screen.flush()?; + continue; + } else { + continue; } - go_to_info_line_and_reset(); - print!( - ":{}", - &command.iter().collect::(), - ); - move_to(current_pos, 2); - screen.flush()?; - continue; } else { continue; } - } else { - continue; } } - } - match code { - KeyCode::Esc => { + (KeyCode::Esc, KeyModifiers::NONE) => { go_to_info_line_and_reset(); hide_cursor(); state.move_cursor(state.layout.y); break 'command; } - KeyCode::Left => { + (KeyCode::Left, KeyModifiers::NONE) => { if current_char_pos == 0 { continue; }; @@ -2014,7 +2012,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> { } } - KeyCode::Right => { + (KeyCode::Right, KeyModifiers::NONE) => { if current_char_pos == command.len() { continue; }; @@ -2029,7 +2027,8 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> { } } - KeyCode::Backspace => { + (KeyCode::Backspace, KeyModifiers::NONE) + | (KeyCode::Char('h'), KeyModifiers::CONTROL) => { if current_char_pos == 0 { continue; }; @@ -2049,7 +2048,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> { } } - KeyCode::Char(c) => { + (KeyCode::Char(c), KeyModifiers::NONE) => { if let Some(to_be_added) = unicode_width::UnicodeWidthChar::width(c) { @@ -2071,7 +2070,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> { } } - KeyCode::Enter => { + (KeyCode::Enter, KeyModifiers::NONE) => { hide_cursor(); //Set the command and argument(s). let commands: String = command.iter().collect(); -- cgit v1.2.3 From e82b2ce7baab98d1367a75a0b6faff23b7ba2fde Mon Sep 17 00:00:00 2001 From: Kyohei Uto Date: Sat, 9 Dec 2023 06:08:51 +0900 Subject: v2.11.0 --- CHANGELOG.md | 6 ++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 5 +++++ src/help.rs | 1 + 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0febc0a..3334892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ ## Unreleased +## v2.11.0 (2023-12-09) + +### Added + +- `` for Backspace functionality after `i`, `I`, `c`, `/`, `:` and `z`. + ## v2.10.2 (2023-11-26) ### Fixed diff --git a/Cargo.lock b/Cargo.lock index 85a9308..9d6f2b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -330,7 +330,7 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "felix" -version = "2.10.2" +version = "2.11.0" dependencies = [ "bwrap", "chrono", diff --git a/Cargo.toml b/Cargo.toml index a85d504..790b3fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "felix" -version = "2.10.2" +version = "2.11.0" authors = ["Kyohei Uto "] edition = "2021" description = "tui file manager with vim-like key mapping" diff --git a/README.md b/README.md index e9899e3..3d3289f 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,11 @@ For more detailed document, visit https://kyoheiu.dev/felix. ## New release +## v2.11.0 (2023-12-09) + +### Added + +- `` for Backspace functionality after `i`, `I`, `c`, `/`, `:` and `z`. ## v2.10.2 (2023-11-26) ### Fixed diff --git a/src/help.rs b/src/help.rs index 7acc8ae..fa49c0d 100644 --- a/src/help.rs +++ b/src/help.rs @@ -74,6 +74,7 @@ N :Go backward to the item that matches the keyword. :q :Exit. :{command} :Execute a command e.g. :zip test *.md :Return to the normal mode. + :Works as Backspace after `i`, `I`, `c`, `/`, `:` and `z`. ZZ :Exit without cd to last working directory (if `match_vim_exit_behavior` is `false`). ZQ :cd into the last working directory and exit -- cgit v1.2.3