Patchwork D11644: chistedit: move changemode() onto state class

login
register
mail settings
Submitter phabricator
Date Oct. 12, 2021, 5:07 p.m.
Message ID <differential-rev-PHID-DREV-ymopli272gfab4byo4hw-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49968/
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/D11644

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,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: