Patchwork D11648: chistedit: move cycleaction() onto state class

login
register
mail settings
Submitter phabricator
Date Oct. 12, 2021, 5:07 p.m.
Message ID <differential-rev-PHID-DREV-sqd5dxqvboigi3zwqczo-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49972/
State Superseded
Headers show

Comments

phabricator - Oct. 12, 2021, 5:07 p.m.
martinvonz created this revision.
Herald added a reviewer: durin42.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11648

AFFECTED FILES
  hgext/histedit.py

CHANGE DETAILS




To: martinvonz, durin42, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1194,23 +1194,6 @@ 
 
 
 # ============ EVENTS ===============
-def cycleaction(state, pos, next=False):
-    """Changes the action state the next or the previous action from
-    the action list"""
-    rules = state.rules
-    assert 0 <= pos < len(rules)
-    current = rules[pos].action
-
-    assert current in KEY_LIST
-
-    index = KEY_LIST.index(current)
-    if next:
-        index += 1
-    else:
-        index -= 1
-    state.change_action(pos, KEY_LIST[index % len(KEY_LIST)])
-
-
 def changeview(state, delta, unit):
     """Change the region of whatever is being viewed (a patch or the list of
     changesets). 'delta' is an amount (+/- 1) and 'unit' is 'page' or 'line'."""
@@ -1486,9 +1469,9 @@ 
             if selected is not None or action == b'move-up':
                 self.swap(oldpos, newpos)
         elif action == b'next-action':
-            cycleaction(self, oldpos, next=True)
+            self.cycle_action(oldpos, next=True)
         elif action == b'prev-action':
-            cycleaction(self, oldpos, next=False)
+            self.cycle_action(oldpos, next=False)
         elif action == b'select':
             selected = oldpos if selected is None else None
             self.make_selection(selected)
@@ -1587,6 +1570,22 @@ 
         assert 0 <= pos < len(rules)
         rules[pos].action = action
 
+    def cycle_action(self, pos, next=False):
+        """Changes the action state the next or the previous action from
+        the action list"""
+        rules = self.rules
+        assert 0 <= pos < len(rules)
+        current = rules[pos].action
+
+        assert current in KEY_LIST
+
+        index = KEY_LIST.index(current)
+        if next:
+            index += 1
+        else:
+            index -= 1
+        self.change_action(pos, KEY_LIST[index % len(KEY_LIST)])
+
 
 def _chisteditmain(repo, rules, stdscr):
     try: