changeset 48213:1302905b2d49

chistedit: move changeview() onto state class Differential Revision: https://phab.mercurial-scm.org/D11649
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 12 Oct 2021 09:41:11 -0700
parents 7913f533592d
children 1895027c5051
files hgext/histedit.py
diffstat 1 files changed, 19 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Tue Oct 12 09:38:04 2021 -0700
+++ b/hgext/histedit.py	Tue Oct 12 09:41:11 2021 -0700
@@ -1193,23 +1193,6 @@
         return self.conflicts
 
 
-# ============ EVENTS ===============
-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'."""
-    mode, _ = state.mode
-    if mode != MODE_PATCH:
-        return
-    mode_state = state.modes[mode]
-    num_lines = len(mode_state[b'patchcontents'])
-    page_height = state.page_height
-    unit = page_height if unit == b'page' else 1
-    num_pages = 1 + (num_lines - 1) // page_height
-    max_offset = (num_pages - 1) * page_height
-    newline = mode_state[b'line_offset'] + delta * unit
-    mode_state[b'line_offset'] = max(0, min(max_offset, newline))
-
-
 def makecommands(rules):
     """Returns a list of commands consumable by histedit --commands based on
     our list of rules"""
@@ -1586,6 +1569,21 @@
             index -= 1
         self.change_action(pos, KEY_LIST[index % len(KEY_LIST)])
 
+    def change_view(self, 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'."""
+        mode, _ = self.mode
+        if mode != MODE_PATCH:
+            return
+        mode_state = self.modes[mode]
+        num_lines = len(mode_state[b'patchcontents'])
+        page_height = self.page_height
+        unit = page_height if unit == b'page' else 1
+        num_pages = 1 + (num_lines - 1) // page_height
+        max_offset = (num_pages - 1) * page_height
+        newline = mode_state[b'line_offset'] + delta * unit
+        mode_state[b'line_offset'] = max(0, min(max_offset, newline))
+
 
 def _chisteditmain(repo, rules, stdscr):
     try:
@@ -1657,13 +1655,13 @@
 
             if e in (E_PAGEDOWN, E_PAGEUP, E_LINEDOWN, E_LINEUP):
                 if e == E_PAGEDOWN:
-                    changeview(state, +1, b'page')
+                    state.change_view(+1, b'page')
                 elif e == E_PAGEUP:
-                    changeview(state, -1, b'page')
+                    state.change_view(-1, b'page')
                 elif e == E_LINEDOWN:
-                    changeview(state, +1, b'line')
+                    state.change_view(+1, b'line')
                 elif e == E_LINEUP:
-                    changeview(state, -1, b'line')
+                    state.change_view(-1, b'line')
 
             # start rendering
             commitwin.erase()