code: def save_to_undo_stack(self, clear_redo_stack=True):
          
          # Safe if the text is different from the text at the top of the stack
          # is different. If the text is the same, just update the cursor position.
          if self._undo_stack and self._undo_stack[-1][0] == self.text:
              self._undo_stack[-1] = (self._undo_stack[-1][0], self.cursor_position)
          else:
              self._undo_stack.append((self.text, self.cursor_position))
  
          # Saving anything to the undo stack, clears the redo stack.
          if clear_redo_stack:
              self._redo_stack = []
docs: Safe current state (input text and cursor position), so that we can
          restore it by calling undo.