Patchwork D11649: chistedit: move changeview() onto state class

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

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
@@ -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()