Patchwork crecord: make enter move cursor down to the next item of the same type

login
register
mail settings
Submitter Anton Shestakov
Date Oct. 13, 2018, 10:08 a.m.
Message ID <652b73cc2aa892cf2c2a.1539425300@s20>
Download mbox | patch
Permalink /patch/35867/
State Accepted
Headers show

Comments

Anton Shestakov - Oct. 13, 2018, 10:08 a.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1539424350 -7200
#      Sat Oct 13 11:52:30 2018 +0200
# Node ID 652b73cc2aa892cf2c2a5988a339ee242d2e1696
# Parent  8278491d01838a2062ba7202be9b79cc6b243c83
crecord: make enter move cursor down to the next item of the same type

Let's replace experimental.spacemovesdown with a separate key: Enter, since it
wasn't used for anything in crecord. Not sure if '\n' works on Windows though.

nextsametype() strictly only moves to items of the same type as the current
item. This, for example, allows to go over individual lines in a diff and skip
hunk and file headers (which would toggle multiple lines).
Augie Fackler - Oct. 13, 2018, 1:37 p.m.
> On Oct 13, 2018, at 12:08, Anton Shestakov <av6@dwimlabs.net> wrote:
> 
> # HG changeset patch
> # User Anton Shestakov <av6@dwimlabs.net>
> # Date 1539424350 -7200
> #      Sat Oct 13 11:52:30 2018 +0200
> # Node ID 652b73cc2aa892cf2c2a5988a339ee242d2e1696
> # Parent  8278491d01838a2062ba7202be9b79cc6b243c83
> crecord: make enter move cursor down to the next item of the same type

queued, very nice

Patch

diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -607,9 +607,6 @@  coreconfigitem('experimental', 'single-h
 coreconfigitem('experimental', 'sshserver.support-v2',
     default=False,
 )
-coreconfigitem('experimental', 'spacemovesdown',
-    default=False,
-)
 coreconfigitem('experimental', 'sparse-read',
     default=False,
 )
diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -713,6 +713,24 @@  class curseschunkselector(object):
         self.currentselecteditem = nextitem
         self.recenterdisplayedarea()
 
+    def nextsametype(self):
+        currentitem = self.currentselecteditem
+        sametype = lambda item: isinstance(item, type(currentitem))
+        nextitem = currentitem.nextitem()
+
+        while nextitem is not None and not sametype(nextitem):
+            nextitem = nextitem.nextitem()
+
+        if nextitem is None:
+            nextitem = currentitem
+        else:
+            parent = nextitem.parentitem()
+            if parent.folded:
+                self.togglefolded(parent)
+
+        self.currentselecteditem = nextitem
+        self.recenterdisplayedarea()
+
     def rightarrowevent(self):
         """
         select (if possible) the first of this item's child-items.
@@ -1027,8 +1045,8 @@  class curseschunkselector(object):
     def _getstatuslinesegments(self):
         """-> [str]. return segments"""
         selected = self.currentselecteditem.applied
-        spaceselect = _('space: select')
-        spacedeselect = _('space: deselect')
+        spaceselect = _('space/enter: select')
+        spacedeselect = _('space/enter: deselect')
         # Format the selected label into a place as long as the longer of the
         # two possible labels.  This may vary by language.
         spacelen = max(len(spaceselect), len(spacedeselect))
@@ -1433,6 +1451,7 @@  can use crecord multiple times to split 
 the following are valid keystrokes:
 
                 [space] : (un-)select item ([~]/[x] = partly/fully applied)
+                [enter] : (un-)select item and go to next item of same type
                       A : (un-)select all items
     up/down-arrow [k/j] : go to previous/next unfolded item
         pgup/pgdn [K/J] : go to previous/next item of same type
@@ -1686,8 +1705,9 @@  are you sure you want to review/edit and
             return True
         elif keypressed in [' '] or (test and keypressed in ["TOGGLE"]):
             self.toggleapply()
-            if self.ui.configbool('experimental', 'spacemovesdown'):
-                self.downarrowevent()
+        elif keypressed in ['\n', 'KEY_ENTER']:
+            self.toggleapply()
+            self.nextsametype()
         elif keypressed in ['A']:
             self.toggleall()
         elif keypressed in ['e']:
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
@@ -327,24 +327,6 @@  reflect this edition.
   hello world
   lower
 
-Check spacemovesdown
-
-  $ cat <<EOF >> $HGRCPATH
-  > [experimental]
-  > spacemovesdown = true
-  > EOF
-  $ cat <<EOF >testModeCommands
-  > TOGGLE
-  > TOGGLE
-  > X
-  > EOF
-  $ hg status -q
-  M b
-  M x
-  $ hg commit -i -m "nothing to commit?" -d "0 0"
-  no changes to record
-  [1]
-
 Check ui.interface logic for the chunkselector
 
 The default interface is text