changeset 48220:7d2464b6e30b

chistedit: move changemode() onto state class Differential Revision: https://phab.mercurial-scm.org/D11644
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 12 Oct 2021 09:16:14 -0700
parents fb30ad66a572
children 0f498e03b016
files hgext/histedit.py
diffstat 1 files changed, 9 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Tue Oct 12 09:00:51 2021 -0700
+++ b/hgext/histedit.py	Tue Oct 12 09:16:14 2021 -0700
@@ -1194,13 +1194,6 @@
 
 
 # ============ EVENTS ===============
-def changemode(state, mode):
-    curmode, _ = state.mode
-    state.mode = (mode, curmode)
-    if mode == MODE_PATCH:
-        state.modes[MODE_PATCH][b'patchcontents'] = state.patch_contents()
-
-
 def makeselection(state, pos):
     state.selected = pos
 
@@ -1541,9 +1534,9 @@
         elif action.startswith(b'action-'):
             changeaction(self, oldpos, action[7:])
         elif action == b'showpatch':
-            changemode(self, MODE_PATCH if curmode != MODE_PATCH else prevmode)
+            self.change_mode(MODE_PATCH if curmode != MODE_PATCH else prevmode)
         elif action == b'help':
-            changemode(self, MODE_HELP if curmode != MODE_HELP else prevmode)
+            self.change_mode(MODE_HELP if curmode != MODE_HELP else prevmode)
         elif action == b'quit':
             return E_QUIT
         elif action == b'histedit':
@@ -1591,6 +1584,12 @@
         # Reset the patch view region to the top of the new patch.
         self.modes[MODE_PATCH][b'line_offset'] = 0
 
+    def change_mode(self, mode):
+        curmode, _ = self.mode
+        self.mode = (mode, curmode)
+        if mode == MODE_PATCH:
+            self.modes[MODE_PATCH][b'patchcontents'] = self.patch_contents()
+
 
 def _chisteditmain(repo, rules, stdscr):
     try:
@@ -1633,7 +1632,7 @@
     while True:
         oldmode, unused = state.mode
         if oldmode == MODE_INIT:
-            changemode(state, MODE_RULES)
+            state.change_mode(MODE_RULES)
         e = state.event(ch)
 
         if e == E_QUIT: