Skip to content

Commit 5de6d57

Browse files
committed
Fix key release bindings and unsaved confirmation
1 parent 02f7ef3 commit 5de6d57

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

scripts/python_learning_editor.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def _bind_events(self) -> None:
284284
self.text.bind("<ButtonRelease>", self._update_helper_panel)
285285
self.text.bind("<Control-space>", self._show_autocomplete)
286286
self.text.bind("<Motion>", self._update_status_bar)
287-
self.text.bind("<KeyRelease>", self._update_status_bar)
287+
self.text.bind("<KeyRelease>", self._update_status_bar, add="+")
288288
self.text.bind("<<Selection>>", self._update_helper_panel)
289289
self.text.bind("<F5>", lambda event: self._run_event(self.run_code))
290290
self.text.bind("<Shift-F5>", lambda event: self._run_event(self.run_selection))
@@ -525,13 +525,20 @@ def save_file_as(self) -> None:
525525
self.save_file()
526526

527527
def _confirm_unsaved_changes(self) -> bool:
528-
if self.text.edit_modified():
529-
answer = messagebox.askyesnocancel("Unsaved changes", "Save the current file before proceeding?")
530-
if answer is None:
528+
if not self.text.edit_modified():
529+
return True
530+
531+
answer = messagebox.askyesnocancel(
532+
"Unsaved changes", "Save the current file before proceeding?"
533+
)
534+
if answer is None:
535+
return False
536+
if answer:
537+
self.save_file()
538+
if self.text.edit_modified():
531539
return False
532-
if answer:
533-
self.save_file()
534-
self.text.edit_modified(False)
540+
else:
541+
self.text.edit_modified(False)
535542
return True
536543

537544
def _undo(self) -> None:

0 commit comments

Comments
 (0)