inserted or deleted.
Otherwise set the flag to the boolean *arg*.
+ .. method:: edit_canundo()
+
+ Return ``True`` if there is an edit action on the undo stack that can be
+ undone, and ``False`` otherwise.
+
+ .. versionadded:: next
+
+ .. method:: edit_canredo()
+
+ Return ``True`` if there is an edit action on the redo stack that can be
+ reapplied, and ``False`` otherwise.
+
+ .. versionadded:: next
+
.. method:: edit_undo()
Undo the most recent edit action, that is, all the inserts and deletes
a string, even if it is already safe for a shell without being quoted.
(Contributed by Jay Berry in :gh:`148846`.)
+tkinter
+-------
+
+* Added new :class:`!tkinter.Text` methods :meth:`~tkinter.Text.edit_canundo`
+ and :meth:`~tkinter.Text.edit_canredo` which return whether an undo or redo
+ is possible.
+ (Contributed by Serhiy Storchaka in :gh:`151674`.)
+
xml
---
text.edit_reset()
self.assertRaises(TclError, text.edit_undo)
+ def test_edit_canundo_canredo(self):
+ text = self.text
+ text.configure(undo=True)
+
+ self.assertIs(text.edit_canundo(), False)
+ self.assertIs(text.edit_canredo(), False)
+
+ text.insert('1.0', 'spam')
+ self.assertIs(text.edit_canundo(), True)
+ self.assertIs(text.edit_canredo(), False)
+
+ text.edit_undo()
+ self.assertIs(text.edit_canundo(), False)
+ self.assertIs(text.edit_canredo(), True)
+
+ text.edit_redo()
+ self.assertIs(text.edit_canundo(), True)
+ self.assertIs(text.edit_canredo(), False)
+
+ text.edit_reset()
+ self.assertIs(text.edit_canundo(), False)
+ self.assertIs(text.edit_canredo(), False)
+
def test_dump(self):
text = self.text
text.insert('1.0', 'hello')
"""
return self.tk.call(self._w, 'edit', *args)
+ def edit_canredo(self):
+ """Return whether redo is possible.
+
+ Return True if redo is possible, i.e. when the redo stack is
+ not empty, and False otherwise.
+ """
+ return self.tk.getboolean(self.edit("canredo"))
+
+ def edit_canundo(self):
+ """Return whether undo is possible.
+
+ Return True if undo is possible, i.e. when the undo stack is
+ not empty, and False otherwise.
+ """
+ return self.tk.getboolean(self.edit("canundo"))
+
def edit_modified(self, arg=None):
"""Get or Set the modified flag
--- /dev/null
+Add the :meth:`~tkinter.Text.edit_canundo` and :meth:`~tkinter.Text.edit_canredo`
+methods of :class:`!tkinter.Text`, wrapping the Tk ``edit canundo`` and
+``edit canredo`` subcommands.