zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: cursor position after vi yank
Date: Fri, 24 Oct 2014 00:06:30 +0200	[thread overview]
Message-ID: <4410.1414101990@thecus.kiddle.eu> (raw)

When producing the test cases, I noticed that zsh is not quite matching
vi in terms of cursor positioning after a yank. This fixes that.

Oliver

diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c
index 20cece0..53919e3 100644
--- a/Src/Zle/zle_vi.c
+++ b/Src/Zle/zle_vi.c
@@ -457,7 +457,14 @@ viyank(UNUSED(char **args))
 	ret = 0;
     }
     vichgflag = 0;
-    zlecs = oldcs;
+    /* cursor now at the start of the range yanked. For line mode
+     * restore the column position */
+    if (vilinerange) {
+	while (oldcs > 0 && zleline[oldcs - 1] != ZWC('\n') &&
+		zlecs != zlell && zleline[zlecs] != ZWC('\n')) {
+	    ++zlecs; --oldcs;
+	}
+    }
     return ret;
 }
 
diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst
index b4426a8..d9fa0d5 100644
--- a/Test/X02zlevi.ztst
+++ b/Test/X02zlevi.ztst
@@ -15,6 +15,28 @@
 >BUFFER: good
 >CURSOR: 4
 
+  zletest $'one two\eyb'
+0:yank left moves the cursor
+>BUFFER: one two
+>CURSOR: 4
+
+  zletest $'one two\e0ye'
+0:yank right leaves the cursor
+>BUFFER: one two
+>CURSOR: 0
+
+  zletest $'short\eoand longer\eyk'
+0:yank up line moves cursor up but not to buffer start
+>BUFFER: short
+>and longer
+>CURSOR: 4
+
+  zletest $'one\eotwo\ekyj'
+0:yank down line leaves the cursor
+>BUFFER: one
+>two
+>CURSOR: 2
+
   zletest $'yankee doodle\ebhDyy0"1P'
 0:paste register 1 to get last deletion
 >BUFFER:  doodleyankee


             reply	other threads:[~2014-10-23 22:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-23 22:06 Oliver Kiddle [this message]
2014-10-24 22:44 ` Oliver Kiddle
2014-10-25  2:27   ` Mikael Magnusson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4410.1414101990@thecus.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).