comparison hgext/histedit.py @ 48212:7913f533592d

chistedit: move cycleaction() onto state class Differential Revision: https://phab.mercurial-scm.org/D11648
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 12 Oct 2021 09:38:04 -0700
parents 141aafac446c
children 1302905b2d49
comparison
equal deleted inserted replaced
48211:141aafac446c 48212:7913f533592d
1192 self.conflicts.remove(other) 1192 self.conflicts.remove(other)
1193 return self.conflicts 1193 return self.conflicts
1194 1194
1195 1195
1196 # ============ EVENTS =============== 1196 # ============ EVENTS ===============
1197 def cycleaction(state, pos, next=False):
1198 """Changes the action state the next or the previous action from
1199 the action list"""
1200 rules = state.rules
1201 assert 0 <= pos < len(rules)
1202 current = rules[pos].action
1203
1204 assert current in KEY_LIST
1205
1206 index = KEY_LIST.index(current)
1207 if next:
1208 index += 1
1209 else:
1210 index -= 1
1211 state.change_action(pos, KEY_LIST[index % len(KEY_LIST)])
1212
1213
1214 def changeview(state, delta, unit): 1197 def changeview(state, delta, unit):
1215 """Change the region of whatever is being viewed (a patch or the list of 1198 """Change the region of whatever is being viewed (a patch or the list of
1216 changesets). 'delta' is an amount (+/- 1) and 'unit' is 'page' or 'line'.""" 1199 changesets). 'delta' is an amount (+/- 1) and 'unit' is 'page' or 'line'."""
1217 mode, _ = state.mode 1200 mode, _ = state.mode
1218 if mode != MODE_PATCH: 1201 if mode != MODE_PATCH:
1484 newpos = max(0, oldpos - 1) 1467 newpos = max(0, oldpos - 1)
1485 self.move_cursor(oldpos, newpos) 1468 self.move_cursor(oldpos, newpos)
1486 if selected is not None or action == b'move-up': 1469 if selected is not None or action == b'move-up':
1487 self.swap(oldpos, newpos) 1470 self.swap(oldpos, newpos)
1488 elif action == b'next-action': 1471 elif action == b'next-action':
1489 cycleaction(self, oldpos, next=True) 1472 self.cycle_action(oldpos, next=True)
1490 elif action == b'prev-action': 1473 elif action == b'prev-action':
1491 cycleaction(self, oldpos, next=False) 1474 self.cycle_action(oldpos, next=False)
1492 elif action == b'select': 1475 elif action == b'select':
1493 selected = oldpos if selected is None else None 1476 selected = oldpos if selected is None else None
1494 self.make_selection(selected) 1477 self.make_selection(selected)
1495 elif action == b'goto' and int(ch) < len(rules) and len(rules) <= 10: 1478 elif action == b'goto' and int(ch) < len(rules) and len(rules) <= 10:
1496 newrule = next((r for r in rules if r.origpos == int(ch))) 1479 newrule = next((r for r in rules if r.origpos == int(ch)))
1584 def change_action(self, pos, action): 1567 def change_action(self, pos, action):
1585 """Change the action state on the given position to the new action""" 1568 """Change the action state on the given position to the new action"""
1586 rules = self.rules 1569 rules = self.rules
1587 assert 0 <= pos < len(rules) 1570 assert 0 <= pos < len(rules)
1588 rules[pos].action = action 1571 rules[pos].action = action
1572
1573 def cycle_action(self, pos, next=False):
1574 """Changes the action state the next or the previous action from
1575 the action list"""
1576 rules = self.rules
1577 assert 0 <= pos < len(rules)
1578 current = rules[pos].action
1579
1580 assert current in KEY_LIST
1581
1582 index = KEY_LIST.index(current)
1583 if next:
1584 index += 1
1585 else:
1586 index -= 1
1587 self.change_action(pos, KEY_LIST[index % len(KEY_LIST)])
1589 1588
1590 1589
1591 def _chisteditmain(repo, rules, stdscr): 1590 def _chisteditmain(repo, rules, stdscr):
1592 try: 1591 try:
1593 curses.use_default_colors() 1592 curses.use_default_colors()