Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/idlelib/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,8 @@ def get_saved(self):
def set_saved(self, flag):
self.undo.set_saved(flag)

def reset_undo(self):
self.undo.reset_undo()
def reset_undo(self, set_saved_flag=True):
self.undo.reset_undo(set_saved_flag)

def short_title(self):
filename = self.io.filename
Expand Down
32 changes: 32 additions & 0 deletions Lib/idlelib/idle_test/test_undo.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,38 @@ def test_dump_event(self):
text.event_generate('<<undo>>')
self.assertTupleEqual((d.pointer, d.can_merge), (2, False))

def test_reset_undo(self):
eq = self.assertEqual
d = self.delegator
orig_sch = d.saved_change_hook
d.saved_change_hook = Mock()

def set_text():
self.text.insert('insert', 'spam')
self.text.insert('insert', '\n')
self.text.insert('insert', 'this is the second line')

set_text()
eq(d.pointer, len(d.undolist))
self.assertNotEqual(d.pointer, d.saved)

# Default to set_saved_flag to True.
d.reset_undo()
eq(d.pointer, 0)
eq(d.undolist, [])
eq(d.undoblock, 0)
eq(d.saved, d.pointer)

# Don't mark as saved upon reset.
set_text()
d.reset_undo(False)
eq(d.pointer, 0)
eq(d.undolist, [])
eq(d.undoblock, 0)
eq(d.saved, -1)

d.saved_change_hook = orig_sch

def test_get_set_saved(self):
# test the getter method get_saved
# test the setter method set_saved
Expand Down
4 changes: 2 additions & 2 deletions Lib/idlelib/iomenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def get_saved(self):
def set_saved(self, flag):
self.editwin.set_saved(flag)

def reset_undo(self):
self.editwin.reset_undo()
def reset_undo(self, set_saved_flag=True):
self.editwin.reset_undo(set_saved_flag)

filename_change_hook = None

Expand Down
14 changes: 13 additions & 1 deletion Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,18 @@ def restart_shell(self, event=None):
self.interp.restart_subprocess(with_cwd=True)

def showprompt(self):
"""Display the prompt in the shell window.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Display the prompt in the shell window.
"Display the prompt."

and delete rest. I will soon propose changing handing of prompt.


Before the prompt is displayed, the text from the prior
prompt is stored in history and the text marks are moved
ahead to end of the text. Once the prompt is written, the
text mark is set to capture insertions and the line and
column within the status bar is updated. Also, the buffer
for undo and redo is cleared as the shell only allows
that functionality on the current line. reset_undo is
called with a saved_flag of False so that clearing the
undo doesn't also get marked as a file save.
"""
self.resetoutput()
try:
s = str(sys.ps1)
Expand All @@ -1255,7 +1267,7 @@ def showprompt(self):
self.console.write(s)
self.text.mark_set("insert", "end-1c")
self.set_line_and_column()
self.io.reset_undo()
self.io.reset_undo(set_saved_flag=False)

def resetoutput(self):
source = self.text.get("iomark", "end-1c")
Expand Down
13 changes: 11 additions & 2 deletions Lib/idlelib/undo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,19 @@ def dump_event(self, event):
pprint(self.undolist[self.pointer:])
return "break"

def reset_undo(self):
def reset_undo(self, set_saved_flag=True):
"""Reset the undo/redo history.

Clear the undo/redo history and optionally set the saved
status for the window based on the parameter. If set_saved_flag
is True, then the window will look like it's been saved. If
it's false, it will not be flagged as saved.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe replacing the 4 lines with "If set_saved_flag, clear the unsaved markers on the title bar." gives the essential additional information needed.

self.was_saved = -1
self.pointer = 0
self.undolist = []
self.undoblock = 0 # or a CommandSequence instance
self.set_saved(1)
self.set_saved(set_saved_flag)

def set_saved(self, flag):
if flag:
Expand Down Expand Up @@ -355,6 +362,8 @@ def _undo_delegator(parent): # htest #
undo.pack(side='left')
redo = Button(undowin, text="Redo", command=lambda:d.redo_event(None))
redo.pack(side='left')
reset = Button(undowin, text="Reset Undo", command=lambda:d.reset_undo())
reset.pack(side='left')
dump = Button(undowin, text="Dump", command=lambda:d.dump_event(None))
dump.pack(side='left')

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix use of unsaved indicator in titlebar of shell window.