zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Enable linewise edit-command when in visual-line
@ 2023-08-21 14:13 Christoffer Lundell
  2023-08-23  3:27 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Christoffer Lundell @ 2023-08-21 14:13 UTC (permalink / raw)
  To: zsh-workers

Change behavior of edit-command in visual-line mode to edit command linewise
instead of only allowing editing of the text between MARK and CURSOR.

The rationale being that in visual-line mode the entire line(s) appears visually
selected, and so I expect edit-command to operate on the entire line(s).

With this patch everything visually selected will be brought into the editor,
while preserving cursor position where applicable.

I am not entirely sure I handle this correctly, though it appears to work fine
when tested locally with both emacs and vim.

---
 Functions/Zle/edit-command-line | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line
index 5f7ea321f..52246b88f 100644
--- a/Functions/Zle/edit-command-line
+++ b/Functions/Zle/edit-command-line
@@ -11,7 +11,7 @@ local left right prebuffer buffer=$BUFFER lbuffer=$LBUFFER
 local TMPSUFFIX=.zsh
 # set up parameters depending on which context we are called from,
 # see below comment for more details
-if (( REGION_ACTIVE )); then
+if (( REGION_ACTIVE == 1 )); then
   if (( CURSOR < MARK )); then
     left=$CURSOR right=$MARK
     lbuffer=
@@ -21,6 +21,23 @@ if (( REGION_ACTIVE )); then
   fi
   (( left++ ))
   buffer=$BUFFER[left,right]
+elif (( REGION_ACTIVE == 2 )); then
+  local mark_left mark_right offset_right
+  if (( CURSOR < MARK )); then
+    mark_left=$CURSOR mark_right=$MARK
+  else
+    mark_left=$MARK mark_right=$CURSOR
+  fi
+  left=${(SB)${BUFFER[1,mark_left]}%$'\n'}
+  (( left != 1 )) && (( left++ ))
+  offset_right=${(SB)${BUFFER[mark_right+1,-1]}#$'\n'}
+  if (( offset_right == 1 )); then
+    right=$#BUFFER
+  else
+    (( right = mark_right + offset_right - 1 ))
+  fi
+  lbuffer=${lbuffer[left,CURSOR]}
+  buffer=$BUFFER[left,right]
 elif (( ! ZLE_RECURSIVE )); then
   prebuffer=$PREBUFFER
 fi
--
2.41.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-08-27 20:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-21 14:13 [PATCH] Enable linewise edit-command when in visual-line Christoffer Lundell
2023-08-23  3:27 ` Bart Schaefer
2023-08-23  9:06   ` Christoffer Lundell
2023-08-23 17:28     ` Bart Schaefer
2023-08-27 11:38       ` Christoffer Lundell
2023-08-27 20:24         ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).