diff mercurial/crecord.py @ 27914:505a10b504ed stable

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.
author Laurent Charignon <lcharignon@fb.com>
date Wed, 20 Jan 2016 11:21:13 -0800
parents a801d331a022
children fedd81659643
line wrap: on
line diff
--- a/mercurial/crecord.py	Thu Jan 21 02:42:01 2016 +0900
+++ b/mercurial/crecord.py	Wed Jan 20 11:21:13 2016 -0800
@@ -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)