From df09ab598f4645a57013d60c39a08239bf5932aa Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 28 Mar 2024 00:13:34 -0500 Subject: [PATCH] Add forward-char-passive binding This binding is akin to ForwardSingleChar but it is "passive" in that is not intended to affect the meta state of the shell: autocompletions are not accepted if the cursor is at the end of input and it does not have any effect in the completions pager. --- src/input.rs | 1 + src/input_common.rs | 1 + src/reader.rs | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/src/input.rs b/src/input.rs index 7f286a9c8..f72fd743a 100644 --- a/src/input.rs +++ b/src/input.rs @@ -153,6 +153,7 @@ const INPUT_FUNCTION_METADATA: &[InputFunctionMetadata] = &[ make_md(L!("force-repaint"), ReadlineCmd::ForceRepaint), make_md(L!("forward-bigword"), ReadlineCmd::ForwardBigword), make_md(L!("forward-char"), ReadlineCmd::ForwardChar), + make_md(L!("forward-char-passive"), ReadlineCmd::ForwardCharPassive), make_md(L!("forward-jump"), ReadlineCmd::ForwardJump), make_md(L!("forward-jump-till"), ReadlineCmd::ForwardJumpTill), make_md(L!("forward-single-char"), ReadlineCmd::ForwardSingleChar), diff --git a/src/input_common.rs b/src/input_common.rs index ce7b73471..43b91af8a 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -35,6 +35,7 @@ pub enum ReadlineCmd { ForwardChar, BackwardChar, ForwardSingleChar, + ForwardCharPassive, ForwardWord, BackwardWord, ForwardBigword, diff --git a/src/reader.rs b/src/reader.rs index 6caa42e74..5053a039b 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -2511,6 +2511,16 @@ impl ReaderData { self.update_buff_pos(elt, Some(el.position() + 1)); } } + rl::ForwardCharPassive => { + let (elt, el) = self.active_edit_line(); + if self.is_navigating_pager_contents() { + // Do nothing + } else if self.is_at_end(el) { + // Do nothing + } else { + self.update_buff_pos(elt, Some(el.position() + 1)); + } + } rl::BackwardKillWord | rl::BackwardKillPathComponent | rl::BackwardKillBigword => { let style = match c { rl::BackwardKillBigword => MoveWordStyle::Whitespace, @@ -4495,6 +4505,7 @@ fn command_ends_paging(c: ReadlineCmd, focused_on_search_field: bool) -> bool { | rl::HistoryPager | rl::BackwardChar | rl::ForwardChar + | rl::ForwardCharPassive | rl::ForwardSingleChar | rl::UpLine | rl::DownLine