Mercurial > hg-stable
diff hgext/histedit.py @ 48219:fb30ad66a572
chistedit: move movecursor() onto state class
Differential Revision: https://phab.mercurial-scm.org/D11643
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 12 Oct 2021 09:00:51 -0700 |
parents | c7690fabce5f |
children | 7d2464b6e30b |
line wrap: on
line diff
--- a/hgext/histedit.py Tue Oct 12 08:56:56 2021 -0700 +++ b/hgext/histedit.py Tue Oct 12 09:00:51 2021 -0700 @@ -1194,26 +1194,6 @@ # ============ EVENTS =============== -def movecursor(state, oldpos, newpos): - """Change the rule/changeset that the cursor is pointing to, regardless of - current mode (you can switch between patches from the view patch window).""" - state.pos = newpos - - mode, _ = state.mode - if mode == MODE_RULES: - # Scroll through the list by updating the view for MODE_RULES, so that - # even if we are not currently viewing the rules, switching back will - # result in the cursor's rule being visible. - modestate = state.modes[MODE_RULES] - if newpos < modestate[b'line_offset']: - modestate[b'line_offset'] = newpos - elif newpos > modestate[b'line_offset'] + state.page_height - 1: - modestate[b'line_offset'] = newpos - state.page_height + 1 - - # Reset the patch view region to the top of the new patch. - state.modes[MODE_PATCH][b'line_offset'] = 0 - - def changemode(state, mode): curmode, _ = state.mode state.mode = (mode, curmode) @@ -1538,12 +1518,12 @@ return if action in (b'down', b'move-down'): newpos = min(oldpos + 1, len(rules) - 1) - movecursor(self, oldpos, newpos) + self.move_cursor(oldpos, newpos) if selected is not None or action == b'move-down': swap(self, oldpos, newpos) elif action in (b'up', b'move-up'): newpos = max(0, oldpos - 1) - movecursor(self, oldpos, newpos) + self.move_cursor(oldpos, newpos) if selected is not None or action == b'move-up': swap(self, oldpos, newpos) elif action == b'next-action': @@ -1555,7 +1535,7 @@ makeselection(self, selected) elif action == b'goto' and int(ch) < len(rules) and len(rules) <= 10: newrule = next((r for r in rules if r.origpos == int(ch))) - movecursor(self, oldpos, newrule.pos) + self.move_cursor(oldpos, newrule.pos) if selected is not None: swap(self, oldpos, newrule.pos) elif action.startswith(b'action-'): @@ -1592,6 +1572,25 @@ displayer.close() return displayer.hunk[rule.ctx.rev()].splitlines() + def move_cursor(self, oldpos, newpos): + """Change the rule/changeset that the cursor is pointing to, regardless of + current mode (you can switch between patches from the view patch window).""" + self.pos = newpos + + mode, _ = self.mode + if mode == MODE_RULES: + # Scroll through the list by updating the view for MODE_RULES, so that + # even if we are not currently viewing the rules, switching back will + # result in the cursor's rule being visible. + modestate = self.modes[MODE_RULES] + if newpos < modestate[b'line_offset']: + modestate[b'line_offset'] = newpos + elif newpos > modestate[b'line_offset'] + self.page_height - 1: + modestate[b'line_offset'] = newpos - self.page_height + 1 + + # Reset the patch view region to the top of the new patch. + self.modes[MODE_PATCH][b'line_offset'] = 0 + def _chisteditmain(repo, rules, stdscr): try: @@ -1652,7 +1651,7 @@ if curmode != oldmode: state.page_height = sizes[b'main'][0] # Adjust the view to fit the current screen size. - movecursor(state, state.pos, state.pos) + state.move_cursor(state.pos, state.pos) # Pack the windows against the top, each pane spread across the # full width of the screen.