Show More
@@ -1288,71 +1288,6 b' def changeview(state, delta, unit):' | |||
|
1288 | 1288 | mode_state[b'line_offset'] = max(0, min(max_offset, newline)) |
|
1289 | 1289 | |
|
1290 | 1290 | |
|
1291 | def event(state, ch): | |
|
1292 | """Change state based on the current character input | |
|
1293 | ||
|
1294 | This takes the current state and based on the current character input from | |
|
1295 | the user we change the state. | |
|
1296 | """ | |
|
1297 | selected = state.selected | |
|
1298 | oldpos = state.pos | |
|
1299 | rules = state.rules | |
|
1300 | ||
|
1301 | if ch in (curses.KEY_RESIZE, b"KEY_RESIZE"): | |
|
1302 | return E_RESIZE | |
|
1303 | ||
|
1304 | lookup_ch = ch | |
|
1305 | if ch is not None and b'0' <= ch <= b'9': | |
|
1306 | lookup_ch = b'0' | |
|
1307 | ||
|
1308 | curmode, prevmode = state.mode | |
|
1309 | action = KEYTABLE[curmode].get( | |
|
1310 | lookup_ch, KEYTABLE[b'global'].get(lookup_ch) | |
|
1311 | ) | |
|
1312 | if action is None: | |
|
1313 | return | |
|
1314 | if action in (b'down', b'move-down'): | |
|
1315 | newpos = min(oldpos + 1, len(rules) - 1) | |
|
1316 | movecursor(state, oldpos, newpos) | |
|
1317 | if selected is not None or action == b'move-down': | |
|
1318 | swap(state, oldpos, newpos) | |
|
1319 | elif action in (b'up', b'move-up'): | |
|
1320 | newpos = max(0, oldpos - 1) | |
|
1321 | movecursor(state, oldpos, newpos) | |
|
1322 | if selected is not None or action == b'move-up': | |
|
1323 | swap(state, oldpos, newpos) | |
|
1324 | elif action == b'next-action': | |
|
1325 | cycleaction(state, oldpos, next=True) | |
|
1326 | elif action == b'prev-action': | |
|
1327 | cycleaction(state, oldpos, next=False) | |
|
1328 | elif action == b'select': | |
|
1329 | selected = oldpos if selected is None else None | |
|
1330 | makeselection(state, selected) | |
|
1331 | elif action == b'goto' and int(ch) < len(rules) and len(rules) <= 10: | |
|
1332 | newrule = next((r for r in rules if r.origpos == int(ch))) | |
|
1333 | movecursor(state, oldpos, newrule.pos) | |
|
1334 | if selected is not None: | |
|
1335 | swap(state, oldpos, newrule.pos) | |
|
1336 | elif action.startswith(b'action-'): | |
|
1337 | changeaction(state, oldpos, action[7:]) | |
|
1338 | elif action == b'showpatch': | |
|
1339 | changemode(state, MODE_PATCH if curmode != MODE_PATCH else prevmode) | |
|
1340 | elif action == b'help': | |
|
1341 | changemode(state, MODE_HELP if curmode != MODE_HELP else prevmode) | |
|
1342 | elif action == b'quit': | |
|
1343 | return E_QUIT | |
|
1344 | elif action == b'histedit': | |
|
1345 | return E_HISTEDIT | |
|
1346 | elif action == b'page-down': | |
|
1347 | return E_PAGEDOWN | |
|
1348 | elif action == b'page-up': | |
|
1349 | return E_PAGEUP | |
|
1350 | elif action == b'line-down': | |
|
1351 | return E_LINEDOWN | |
|
1352 | elif action == b'line-up': | |
|
1353 | return E_LINEUP | |
|
1354 | ||
|
1355 | ||
|
1356 | 1291 | def makecommands(rules): |
|
1357 | 1292 | """Returns a list of commands consumable by histedit --commands based on |
|
1358 | 1293 | our list of rules""" |
@@ -1591,6 +1526,70 b' pgup/K: move patch up, pgdn/J: move patc' | |||
|
1591 | 1526 | content = self.modes[MODE_PATCH][b'patchcontents'] |
|
1592 | 1527 | self.render_string(win, content[start:], diffcolors=True) |
|
1593 | 1528 | |
|
1529 | def event(self, ch): | |
|
1530 | """Change state based on the current character input | |
|
1531 | ||
|
1532 | This takes the current state and based on the current character input from | |
|
1533 | the user we change the state. | |
|
1534 | """ | |
|
1535 | selected = self.selected | |
|
1536 | oldpos = self.pos | |
|
1537 | rules = self.rules | |
|
1538 | ||
|
1539 | if ch in (curses.KEY_RESIZE, b"KEY_RESIZE"): | |
|
1540 | return E_RESIZE | |
|
1541 | ||
|
1542 | lookup_ch = ch | |
|
1543 | if ch is not None and b'0' <= ch <= b'9': | |
|
1544 | lookup_ch = b'0' | |
|
1545 | ||
|
1546 | curmode, prevmode = self.mode | |
|
1547 | action = KEYTABLE[curmode].get( | |
|
1548 | lookup_ch, KEYTABLE[b'global'].get(lookup_ch) | |
|
1549 | ) | |
|
1550 | if action is None: | |
|
1551 | return | |
|
1552 | if action in (b'down', b'move-down'): | |
|
1553 | newpos = min(oldpos + 1, len(rules) - 1) | |
|
1554 | movecursor(self, oldpos, newpos) | |
|
1555 | if selected is not None or action == b'move-down': | |
|
1556 | swap(self, oldpos, newpos) | |
|
1557 | elif action in (b'up', b'move-up'): | |
|
1558 | newpos = max(0, oldpos - 1) | |
|
1559 | movecursor(self, oldpos, newpos) | |
|
1560 | if selected is not None or action == b'move-up': | |
|
1561 | swap(self, oldpos, newpos) | |
|
1562 | elif action == b'next-action': | |
|
1563 | cycleaction(self, oldpos, next=True) | |
|
1564 | elif action == b'prev-action': | |
|
1565 | cycleaction(self, oldpos, next=False) | |
|
1566 | elif action == b'select': | |
|
1567 | selected = oldpos if selected is None else None | |
|
1568 | makeselection(self, selected) | |
|
1569 | elif action == b'goto' and int(ch) < len(rules) and len(rules) <= 10: | |
|
1570 | newrule = next((r for r in rules if r.origpos == int(ch))) | |
|
1571 | movecursor(self, oldpos, newrule.pos) | |
|
1572 | if selected is not None: | |
|
1573 | swap(self, oldpos, newrule.pos) | |
|
1574 | elif action.startswith(b'action-'): | |
|
1575 | changeaction(self, oldpos, action[7:]) | |
|
1576 | elif action == b'showpatch': | |
|
1577 | changemode(self, MODE_PATCH if curmode != MODE_PATCH else prevmode) | |
|
1578 | elif action == b'help': | |
|
1579 | changemode(self, MODE_HELP if curmode != MODE_HELP else prevmode) | |
|
1580 | elif action == b'quit': | |
|
1581 | return E_QUIT | |
|
1582 | elif action == b'histedit': | |
|
1583 | return E_HISTEDIT | |
|
1584 | elif action == b'page-down': | |
|
1585 | return E_PAGEDOWN | |
|
1586 | elif action == b'page-up': | |
|
1587 | return E_PAGEUP | |
|
1588 | elif action == b'line-down': | |
|
1589 | return E_LINEDOWN | |
|
1590 | elif action == b'line-up': | |
|
1591 | return E_LINEUP | |
|
1592 | ||
|
1594 | 1593 | |
|
1595 | 1594 | def _chisteditmain(repo, rules, stdscr): |
|
1596 | 1595 | try: |
@@ -1634,7 +1633,7 b' def _chisteditmain(repo, rules, stdscr):' | |||
|
1634 | 1633 | oldmode, unused = state.mode |
|
1635 | 1634 | if oldmode == MODE_INIT: |
|
1636 | 1635 | changemode(state, MODE_RULES) |
|
1637 |
e = event( |
|
|
1636 | e = state.event(ch) | |
|
1638 | 1637 | |
|
1639 | 1638 | if e == E_QUIT: |
|
1640 | 1639 | return False |
General Comments 0
You need to be logged in to leave comments.
Login now