From df09ab598f4645a57013d60c39a08239bf5932aa Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 28 Mar 2024 00:13:34 -0500 Subject: [PATCH 1/5] 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 fn make_md(name: &'static wstr, code: ReadlineCmd) -> InputFunctionMetadat 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 @@ fn handle_readline_command(&mut self, c: ReadlineCmd, rls: &mut ReadlineLoopStat 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 From 674c481d87e27fdf222bf261def2fc9fbecd929c Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 28 Mar 2024 00:18:24 -0500 Subject: [PATCH 2/5] Add documentation for forward-char-passive --- doc_src/cmds/bind.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc_src/cmds/bind.rst b/doc_src/cmds/bind.rst index 2f08909fe..99e85524f 100644 --- a/doc_src/cmds/bind.rst +++ b/doc_src/cmds/bind.rst @@ -191,6 +191,10 @@ The following special input functions are available: move one character to the right; or if at the end of the commandline, accept the current autosuggestion. If the completion pager is active, select the next completion instead. +``forward-char-passive`` + move one character to the right, but do not trigger any non-movement-related operations. If the cursor is at the end of the + commandline, does not accept the current autosuggestion (if any). If the completion pager is active, does nothing. + ``forward-single-char`` move one character to the right; or if at the end of the commandline, accept a single char from the current autosuggestion. From 3980e46d3af94d7df38161ba46332dc8335f142b Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 28 Mar 2024 00:46:41 -0500 Subject: [PATCH 3/5] Add test for forward-char-passive --- tests/checks/tmux-complete.fish | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/checks/tmux-complete.fish b/tests/checks/tmux-complete.fish index a9195f21e..25ea48075 100644 --- a/tests/checks/tmux-complete.fish +++ b/tests/checks/tmux-complete.fish @@ -102,3 +102,15 @@ isolated-tmux send-keys C-e M-f Space nothing tmux-sleep isolated-tmux capture-pane -p # CHECK: prompt 7> echo suggest nothing + +isolated-tmux send-keys C-u 'bind \cs forward-char-passive' Enter C-l +isolated-tmux send-keys C-u 'bind \cp backward-char' Enter C-l +isolated-tmux send-keys C-u 'echo do not accept this' Enter C-l +tmux-sleep +isolated-tmux send-keys 'echo do not accept thi' C-p C-p Delete C-p C-s 'h' +tmux-sleep +isolated-tmux send-keys C-s C-s C-s 'x' +tmux-sleep +isolated-tmux capture-pane -p +tmux-sleep +# CHECK: prompt 10> echo do not accept thix From 1adbec2d3785c23da52090bc509c652db81855ca Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 29 Mar 2024 14:09:34 -0500 Subject: [PATCH 4/5] Add backward-char-passive --- src/input.rs | 1 + src/input_common.rs | 1 + src/reader.rs | 19 +++++++++++++------ tests/checks/tmux-complete.fish | 6 ++---- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/input.rs b/src/input.rs index f72fd743a..270ddad08 100644 --- a/src/input.rs +++ b/src/input.rs @@ -119,6 +119,7 @@ const fn make_md(name: &'static wstr, code: ReadlineCmd) -> InputFunctionMetadat make_md(L!("and"), ReadlineCmd::FuncAnd), make_md(L!("backward-bigword"), ReadlineCmd::BackwardBigword), make_md(L!("backward-char"), ReadlineCmd::BackwardChar), + make_md(L!("backward-char-passive"), ReadlineCmd::BackwardCharPassive), make_md(L!("backward-delete-char"), ReadlineCmd::BackwardDeleteChar), make_md(L!("backward-jump"), ReadlineCmd::BackwardJump), make_md(L!("backward-jump-till"), ReadlineCmd::BackwardJumpTill), diff --git a/src/input_common.rs b/src/input_common.rs index 43b91af8a..cd97c6231 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -34,6 +34,7 @@ pub enum ReadlineCmd { EndOfLine, ForwardChar, BackwardChar, + BackwardCharPassive, ForwardSingleChar, ForwardCharPassive, ForwardWord, diff --git a/src/reader.rs b/src/reader.rs index 5053a039b..21742a251 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -2497,6 +2497,14 @@ fn handle_readline_command(&mut self, c: ReadlineCmd, rls: &mut ReadlineLoopStat self.update_buff_pos(elt, Some(el.position() - 1)); } } + rl::BackwardCharPassive => { + let (elt, el) = self.active_edit_line(); + if el.position() != 0 { + if elt == EditableLineTag::SearchField || !self.is_navigating_pager_contents() { + self.update_buff_pos(elt, Some(el.position() - 1)); + } + } + } rl::ForwardChar | rl::ForwardSingleChar => { let (elt, el) = self.active_edit_line(); if self.is_navigating_pager_contents() { @@ -2513,12 +2521,10 @@ fn handle_readline_command(&mut self, c: ReadlineCmd, rls: &mut ReadlineLoopStat } 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)); + if !self.is_at_end(el) { + if elt == EditableLineTag::SearchField || !self.is_navigating_pager_contents() { + self.update_buff_pos(elt, Some(el.position() + 1)); + } } } rl::BackwardKillWord | rl::BackwardKillPathComponent | rl::BackwardKillBigword => { @@ -4504,6 +4510,7 @@ fn command_ends_paging(c: ReadlineCmd, focused_on_search_field: bool) -> bool { | rl::CompleteAndSearch | rl::HistoryPager | rl::BackwardChar + | rl::BackwardCharPassive | rl::ForwardChar | rl::ForwardCharPassive | rl::ForwardSingleChar diff --git a/tests/checks/tmux-complete.fish b/tests/checks/tmux-complete.fish index 25ea48075..81ab019d1 100644 --- a/tests/checks/tmux-complete.fish +++ b/tests/checks/tmux-complete.fish @@ -104,13 +104,11 @@ isolated-tmux capture-pane -p # CHECK: prompt 7> echo suggest nothing isolated-tmux send-keys C-u 'bind \cs forward-char-passive' Enter C-l -isolated-tmux send-keys C-u 'bind \cp backward-char' Enter C-l +isolated-tmux send-keys C-u 'bind \cb backward-char-passive' Enter C-l isolated-tmux send-keys C-u 'echo do not accept this' Enter C-l tmux-sleep -isolated-tmux send-keys 'echo do not accept thi' C-p C-p Delete C-p C-s 'h' +isolated-tmux send-keys 'echo do not accept thi' C-b C-b Delete C-b C-s 'h' tmux-sleep isolated-tmux send-keys C-s C-s C-s 'x' -tmux-sleep isolated-tmux capture-pane -p -tmux-sleep # CHECK: prompt 10> echo do not accept thix From 8eb7a080351806a11145cbaae0a5d57f96565b06 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 29 Mar 2024 14:12:21 -0500 Subject: [PATCH 5/5] Document backward-char-passive --- doc_src/cmds/bind.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/doc_src/cmds/bind.rst b/doc_src/cmds/bind.rst index 99e85524f..9b4f166cf 100644 --- a/doc_src/cmds/bind.rst +++ b/doc_src/cmds/bind.rst @@ -100,6 +100,10 @@ The following special input functions are available: move one character to the left. If the completion pager is active, select the previous completion instead. +``backward-char-passive`` + move one character to the left, but do not trigger any non-movement-related operations. If the cursor is at the start of + the commandline, does nothing. Does not change the selected item in the completion pager UI when shown. + ``backward-bigword`` move one whitespace-delimited word to the left @@ -193,7 +197,8 @@ The following special input functions are available: ``forward-char-passive`` move one character to the right, but do not trigger any non-movement-related operations. If the cursor is at the end of the - commandline, does not accept the current autosuggestion (if any). If the completion pager is active, does nothing. + commandline, does not accept the current autosuggestion (if any). Does not change the selected item in the completion pager, + if shown. ``forward-single-char`` move one character to the right; or if at the end of the commandline, accept a single char from the current autosuggestion.