IDLE: Pasting or typing over a selection requires two Undo steps to undo it. Undo does not restore selection. · Issue #163179 · python/cpython
Repository navigation
IDLE: Pasting or typing over a selection requires two Undo steps to undo it. Undo does not restore selection. #163179
New issue
New issue
Backlog
Backlog
IDLE: Pasting or typing over a selection requires two Undo steps to undo it. Undo does not restore selection. #163179 Labels
topic-IDLE
type-bug
Description
@abs-zer's profile abs-zer opened on Dec 5, 2026Bug report
Summary
In IDLE (both the Shell and Editor windows):
If I Paste (Ctrl+V) over or type over selected text (replacing it), undoing that one action takes two Undo (Ctrl+Z) steps. (The editor handles the paste-over or type-over as a delete followed by an insert, but it does not "group" the two sub-actions. Afterward, my first Undo undoes the insert and then my second Undo undoes the delete.) (Every other editing interface will undo a paste-over or a type-over in only one step.)
Also, undoing a deletion (or a paste or typing over selected text) fails to restore the previous text selection. (Restoring the prior selection is the norm, so that, for example, selecting text, overtyping X, Undoing, and then typing Y replaces the selected text with Y.)
Steps to reproduce
- Open IDLE Shell or an IDLE Editor window.
- Type
foo barand then selectfoo. - While
foois highlighted, type an X. Or, copysnackinto the [system] clipboard and then typeCtrl+Vto paste overworld. - Type
Ctrl+Z(or Edit:Undo). - Type
Ctrl+Z(or Edit:Undo) again. - Type
Ctrl+Shift+Z(or Edit:Redo). - Type
Ctrl+Shift+Z(or Edit:Redo) again.
Actual behavior
- The text is now
X barorsnack bar(as expected). - First Undo: Only removes the typed or pasted text (
xorsnack), leavingbar(with the space). - Second Undo: Restores
foo, leavingfoo bar(delayed success). Does not restore the selection highlight onfoo(incomplete Undo). Repeating the typing or pasting would not have the same effect because the selection has been lost or discarded. - First Redo: Redoes the delete part.
- Second Undo: Redoes the typing or replacement.
Expected behavior
4 Single-step Undo: The first Ctrl+Z should have undone the paste-over (or type-over) as one step. (This allows users to symmetrically Undo and Redo in single steps, for whatever reason, including comparing before-and-after edits).
- Selection restoration: Undoing a cut (
Ctrl+X) or paste-over should restore theselrange so the previously selected text is highlighted again.
6 Single-step Redo: The firstCtrl+Zshould have undone the paste-over (or type-over) as one step. (This allows users to symmetrically Undo and Redo in single steps, for whatever reason, including comparing before-and-after edits).
Cause & suggested fix
- Undo grouping (
Lib/idlelib/editor.py):EditorWindow.paste()generates<<Paste>>without wrapping it inundo_block_start()/undo_block_stop(), so Tk's underlyingdeleteandinsertoperations are recorded as two separate commands onUndoDelegator:def paste(self, event=None): self.text.undo_block_start() try: self.text.event_generate("<<Paste>>") finally: self.text.undo_block_stop() self.text.see("insert") return "break" - Selection restoration (
Lib/idlelib/undo.py):DeleteCommand.undo()reinsertsself.charsatself.index1without re-applying theseltag across(self.index1, self.index2)for multi-character deletions.
CPython versions tested on:
3.15
Operating systems tested on:
Windows
Metadata
Metadata
Assignees
No one assignedLabels
topic-IDLE
type-bug
Projects
- IDLE Issues Status No status