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 swap(state, oldpos, newpos): |
|
1198 """Swap two positions and calculate necessary conflicts in |
|
1199 O(|newpos-oldpos|) time""" |
|
1200 |
|
1201 rules = state.rules |
|
1202 assert 0 <= oldpos < len(rules) and 0 <= newpos < len(rules) |
|
1203 |
|
1204 rules[oldpos], rules[newpos] = rules[newpos], rules[oldpos] |
|
1205 |
|
1206 # TODO: swap should not know about histeditrule's internals |
|
1207 rules[newpos].pos = newpos |
|
1208 rules[oldpos].pos = oldpos |
|
1209 |
|
1210 start = min(oldpos, newpos) |
|
1211 end = max(oldpos, newpos) |
|
1212 for r in pycompat.xrange(start, end + 1): |
|
1213 rules[newpos].checkconflicts(rules[r]) |
|
1214 rules[oldpos].checkconflicts(rules[r]) |
|
1215 |
|
1216 if state.selected: |
|
1217 state.make_selection(newpos) |
|
1218 |
|
1219 |
|
1220 def changeaction(state, pos, action): |
1197 def changeaction(state, pos, action): |
1221 """Change the action state on the given position to the new action""" |
1198 """Change the action state on the given position to the new action""" |
1222 rules = state.rules |
1199 rules = state.rules |
1223 assert 0 <= pos < len(rules) |
1200 assert 0 <= pos < len(rules) |
1224 rules[pos].action = action |
1201 rules[pos].action = action |
1507 return |
1484 return |
1508 if action in (b'down', b'move-down'): |
1485 if action in (b'down', b'move-down'): |
1509 newpos = min(oldpos + 1, len(rules) - 1) |
1486 newpos = min(oldpos + 1, len(rules) - 1) |
1510 self.move_cursor(oldpos, newpos) |
1487 self.move_cursor(oldpos, newpos) |
1511 if selected is not None or action == b'move-down': |
1488 if selected is not None or action == b'move-down': |
1512 swap(self, oldpos, newpos) |
1489 self.swap(oldpos, newpos) |
1513 elif action in (b'up', b'move-up'): |
1490 elif action in (b'up', b'move-up'): |
1514 newpos = max(0, oldpos - 1) |
1491 newpos = max(0, oldpos - 1) |
1515 self.move_cursor(oldpos, newpos) |
1492 self.move_cursor(oldpos, newpos) |
1516 if selected is not None or action == b'move-up': |
1493 if selected is not None or action == b'move-up': |
1517 swap(self, oldpos, newpos) |
1494 self.swap(oldpos, newpos) |
1518 elif action == b'next-action': |
1495 elif action == b'next-action': |
1519 cycleaction(self, oldpos, next=True) |
1496 cycleaction(self, oldpos, next=True) |
1520 elif action == b'prev-action': |
1497 elif action == b'prev-action': |
1521 cycleaction(self, oldpos, next=False) |
1498 cycleaction(self, oldpos, next=False) |
1522 elif action == b'select': |
1499 elif action == b'select': |
1524 self.make_selection(selected) |
1501 self.make_selection(selected) |
1525 elif action == b'goto' and int(ch) < len(rules) and len(rules) <= 10: |
1502 elif action == b'goto' and int(ch) < len(rules) and len(rules) <= 10: |
1526 newrule = next((r for r in rules if r.origpos == int(ch))) |
1503 newrule = next((r for r in rules if r.origpos == int(ch))) |
1527 self.move_cursor(oldpos, newrule.pos) |
1504 self.move_cursor(oldpos, newrule.pos) |
1528 if selected is not None: |
1505 if selected is not None: |
1529 swap(self, oldpos, newrule.pos) |
1506 self.swap(oldpos, newrule.pos) |
1530 elif action.startswith(b'action-'): |
1507 elif action.startswith(b'action-'): |
1531 changeaction(self, oldpos, action[7:]) |
1508 changeaction(self, oldpos, action[7:]) |
1532 elif action == b'showpatch': |
1509 elif action == b'showpatch': |
1533 self.change_mode(MODE_PATCH if curmode != MODE_PATCH else prevmode) |
1510 self.change_mode(MODE_PATCH if curmode != MODE_PATCH else prevmode) |
1534 elif action == b'help': |
1511 elif action == b'help': |
1586 if mode == MODE_PATCH: |
1563 if mode == MODE_PATCH: |
1587 self.modes[MODE_PATCH][b'patchcontents'] = self.patch_contents() |
1564 self.modes[MODE_PATCH][b'patchcontents'] = self.patch_contents() |
1588 |
1565 |
1589 def make_selection(self, pos): |
1566 def make_selection(self, pos): |
1590 self.selected = pos |
1567 self.selected = pos |
|
1568 |
|
1569 def swap(self, oldpos, newpos): |
|
1570 """Swap two positions and calculate necessary conflicts in |
|
1571 O(|newpos-oldpos|) time""" |
|
1572 |
|
1573 rules = self.rules |
|
1574 assert 0 <= oldpos < len(rules) and 0 <= newpos < len(rules) |
|
1575 |
|
1576 rules[oldpos], rules[newpos] = rules[newpos], rules[oldpos] |
|
1577 |
|
1578 # TODO: swap should not know about histeditrule's internals |
|
1579 rules[newpos].pos = newpos |
|
1580 rules[oldpos].pos = oldpos |
|
1581 |
|
1582 start = min(oldpos, newpos) |
|
1583 end = max(oldpos, newpos) |
|
1584 for r in pycompat.xrange(start, end + 1): |
|
1585 rules[newpos].checkconflicts(rules[r]) |
|
1586 rules[oldpos].checkconflicts(rules[r]) |
|
1587 |
|
1588 if self.selected: |
|
1589 self.make_selection(newpos) |
1591 |
1590 |
1592 |
1591 |
1593 def _chisteditmain(repo, rules, stdscr): |
1592 def _chisteditmain(repo, rules, stdscr): |
1594 try: |
1593 try: |
1595 curses.use_default_colors() |
1594 curses.use_default_colors() |