Patchwork [STABLE] crecord: edit during hg crecord should preserve cursor position (issue5041)

login
register
mail settings
Submitter Laurent Charignon
Date Jan. 20, 2016, 7:21 p.m.
Message ID <fa3f8213bdf44094d680.1453317685@dev5073.prn1.facebook.com>
Download mbox | patch
Permalink /patch/12845/
State Accepted
Headers show

Comments

Laurent Charignon - Jan. 20, 2016, 7:21 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1453317673 28800
#      Wed Jan 20 11:21:13 2016 -0800
# Branch stable
# Node ID fa3f8213bdf44094d6804947646458373918ff25
# Parent  3203dfe341f962e33256d6475fc3585563db78ad
crecord: edit during hg crecord should preserve cursor position (issue5041)

This patch adds a variable to keep track of what hunk was selected before the
edit. We use that variable to select the hunk or its replacement after the edit.
Matt Mackall - Jan. 20, 2016, 7:42 p.m.
On Wed, 2016-01-20 at 11:21 -0800, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1453317673 28800
> #      Wed Jan 20 11:21:13 2016 -0800
> # Branch stable
> # Node ID fa3f8213bdf44094d6804947646458373918ff25
> # Parent  3203dfe341f962e33256d6475fc3585563db78ad
> crecord: edit during hg crecord should preserve cursor position (issue5041)

Queued for stable, thanks.
-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -1551,6 +1551,9 @@ 
         if not isinstance(item, uihunk):
             return
 
+        # To go back to that hunk or its replacement at the end of the edit
+        itemindex = item.parentitem().hunks.index(item)
+
         beforeadded, beforeremoved = item.added, item.removed
         newpatches = editpatchwitheditor(self, item)
         if newpatches is None:
@@ -1575,6 +1578,8 @@ 
         if self.emptypatch():
             header.hunks = hunksbefore + [item] + hunksafter
         self.currentselecteditem = header
+        if len(header.hunks) > itemindex:
+            self.currentselecteditem = header.hunks[itemindex]
 
         if not test:
             updateui(self)
diff --git a/tests/test-commit-interactive-curses.t b/tests/test-commit-interactive-curses.t
--- a/tests/test-commit-interactive-curses.t
+++ b/tests/test-commit-interactive-curses.t
@@ -193,3 +193,33 @@ 
   +++ b/x	Thu Jan 01 00:00:00 1970 +0000
   @@ -0,0 +1,1 @@
   +hello world
+
+Editing a hunk puts you back on that hunk when done editing (issue5041)
+To do that, we change two lines in a file, pretend to edit the second line,
+exit, toggle the line selected at the end of the edit and commit.
+The first line should be recorded if we were put on the second line at the end
+of the edit.
+
+  $ hg update -C .
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ echo "foo" > x
+  $ echo "hello world" >> x
+  $ echo "bar" >> x
+  $ cat <<EOF >testModeCommands
+  > f
+  > KEY_DOWN
+  > KEY_DOWN
+  > KEY_DOWN
+  > KEY_DOWN
+  > e
+  > TOGGLE
+  > X
+  > EOF
+  $ printf "printf 'editor ran\n'; exit 0" > editor.sh
+  $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit  -i -m "edit hunk" -d "0 0"
+  editor ran
+  $ hg cat -r . x
+  foo
+  hello world
+
+