From patchwork Tue Oct 12 17:07:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D11644: chistedit: move changemode() onto state class From: phabricator X-Patchwork-Id: 49968 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Tue, 12 Oct 2021 17:07:14 +0000 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 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: