Mercurial > hg-stable
comparison hgext/histedit.py @ 48221:0f498e03b016
chistedit: move makeselection() onto state class
Differential Revision: https://phab.mercurial-scm.org/D11645
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 12 Oct 2021 09:17:59 -0700 |
parents | 7d2464b6e30b |
children | 0444956ecbcf |
comparison
equal
deleted
inserted
replaced
48220:7d2464b6e30b | 48221:0f498e03b016 |
---|---|
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 makeselection(state, pos): | |
1198 state.selected = pos | |
1199 | |
1200 | |
1201 def swap(state, oldpos, newpos): | 1197 def swap(state, oldpos, newpos): |
1202 """Swap two positions and calculate necessary conflicts in | 1198 """Swap two positions and calculate necessary conflicts in |
1203 O(|newpos-oldpos|) time""" | 1199 O(|newpos-oldpos|) time""" |
1204 | 1200 |
1205 rules = state.rules | 1201 rules = state.rules |
1216 for r in pycompat.xrange(start, end + 1): | 1212 for r in pycompat.xrange(start, end + 1): |
1217 rules[newpos].checkconflicts(rules[r]) | 1213 rules[newpos].checkconflicts(rules[r]) |
1218 rules[oldpos].checkconflicts(rules[r]) | 1214 rules[oldpos].checkconflicts(rules[r]) |
1219 | 1215 |
1220 if state.selected: | 1216 if state.selected: |
1221 makeselection(state, newpos) | 1217 state.make_selection(newpos) |
1222 | 1218 |
1223 | 1219 |
1224 def changeaction(state, pos, action): | 1220 def changeaction(state, pos, action): |
1225 """Change the action state on the given position to the new action""" | 1221 """Change the action state on the given position to the new action""" |
1226 rules = state.rules | 1222 rules = state.rules |
1523 cycleaction(self, oldpos, next=True) | 1519 cycleaction(self, oldpos, next=True) |
1524 elif action == b'prev-action': | 1520 elif action == b'prev-action': |
1525 cycleaction(self, oldpos, next=False) | 1521 cycleaction(self, oldpos, next=False) |
1526 elif action == b'select': | 1522 elif action == b'select': |
1527 selected = oldpos if selected is None else None | 1523 selected = oldpos if selected is None else None |
1528 makeselection(self, selected) | 1524 self.make_selection(selected) |
1529 elif action == b'goto' and int(ch) < len(rules) and len(rules) <= 10: | 1525 elif action == b'goto' and int(ch) < len(rules) and len(rules) <= 10: |
1530 newrule = next((r for r in rules if r.origpos == int(ch))) | 1526 newrule = next((r for r in rules if r.origpos == int(ch))) |
1531 self.move_cursor(oldpos, newrule.pos) | 1527 self.move_cursor(oldpos, newrule.pos) |
1532 if selected is not None: | 1528 if selected is not None: |
1533 swap(self, oldpos, newrule.pos) | 1529 swap(self, oldpos, newrule.pos) |
1587 def change_mode(self, mode): | 1583 def change_mode(self, mode): |
1588 curmode, _ = self.mode | 1584 curmode, _ = self.mode |
1589 self.mode = (mode, curmode) | 1585 self.mode = (mode, curmode) |
1590 if mode == MODE_PATCH: | 1586 if mode == MODE_PATCH: |
1591 self.modes[MODE_PATCH][b'patchcontents'] = self.patch_contents() | 1587 self.modes[MODE_PATCH][b'patchcontents'] = self.patch_contents() |
1588 | |
1589 def make_selection(self, pos): | |
1590 self.selected = pos | |
1592 | 1591 |
1593 | 1592 |
1594 def _chisteditmain(repo, rules, stdscr): | 1593 def _chisteditmain(repo, rules, stdscr): |
1595 try: | 1594 try: |
1596 curses.use_default_colors() | 1595 curses.use_default_colors() |