Go to a past state of the database. Returns the database to the state associated with the specified mark. Both the identifier of a mark and its name can be used. If the mark is omitted, the last created mark is used. If there are no past marks, or the specified mark
(self, mark: int | str | None = None)
| 2721 | self._curaction += direction |
| 2722 | |
| 2723 | def undo(self, mark: int | str | None = None) -> None: |
| 2724 | """Go to a past state of the database. |
| 2725 | |
| 2726 | Returns the database to the state associated with the specified mark. |
| 2727 | Both the identifier of a mark and its name can be used. If the mark is |
| 2728 | omitted, the last created mark is used. If there are no past |
| 2729 | marks, or the specified mark is not older than the current one, an |
| 2730 | UndoRedoError is raised. |
| 2731 | |
| 2732 | This method can only be called when the Undo/Redo mechanism |
| 2733 | has been enabled. Otherwise, an UndoRedoError |
| 2734 | is raised. |
| 2735 | |
| 2736 | """ |
| 2737 | self._check_open() |
| 2738 | self._check_undo_enabled() |
| 2739 | |
| 2740 | # print("(pre)UNDO: (curaction, curmark) = (%s,%s)" % \ |
| 2741 | # (self._curaction, self._curmark)) |
| 2742 | if mark is None: |
| 2743 | markid = self._curmark |
| 2744 | # Correction if we are settled on top of a mark |
| 2745 | opcode = self._actionlog.cols.opcode |
| 2746 | if opcode[self._curaction] == _op_to_code["MARK"]: |
| 2747 | markid -= 1 |
| 2748 | else: |
| 2749 | # Get the mark ID number |
| 2750 | markid = self._get_mark_id(mark) |
| 2751 | # Get the final action ID to go |
| 2752 | finalaction = self._get_final_action(markid) |
| 2753 | if finalaction > self._curaction: |
| 2754 | raise UndoRedoError( |
| 2755 | "Mark ``%s`` is newer than the current mark. " |
| 2756 | "Use `redo()` or `goto()` instead." % (mark,) |
| 2757 | ) |
| 2758 | |
| 2759 | # The file is going to be changed. |
| 2760 | self._check_writable() |
| 2761 | |
| 2762 | # Try to reach this mark by unwinding actions in the log |
| 2763 | self._doundo(finalaction - 1, -1) |
| 2764 | if self._curaction < self._actionlog.nrows - 1: |
| 2765 | self._curaction += 1 |
| 2766 | self._curmark = int(self._actionlog.cols.arg1[self._curaction]) |
| 2767 | |
| 2768 | # print("(post)UNDO: (curaction, curmark) = (%s,%s)" % \ |
| 2769 | # (self._curaction, self._curmark)) |