diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index a6f595ccf08bf4..8cfd9222c2a849 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -319,6 +319,14 @@ http (Contributed by Yorik Hansen in :gh:`123430`.) +idlelib and IDLE +---------------- + +* If no selection is made during copy/cut, the current line will + copy/cut automatically. + (Contributed by Jiahao Li in :gh:`94521`.) + + inspect ------- diff --git a/Lib/idlelib/News3.txt b/Lib/idlelib/News3.txt index 37ff93f9866e3c..697233255b5e66 100644 --- a/Lib/idlelib/News3.txt +++ b/Lib/idlelib/News3.txt @@ -1,6 +1,15 @@ +What's New in IDLE 3.14.0 +(since 3.13.0) +Released on 2025-10-xx +========================= + + +gh-94521: If no selection is made during copy/cut, the current line +will copy/cut automatically. + What's New in IDLE 3.13.0 (since 3.12.0) -Released on 2024-10-xx +Released on 2024-10-07 ========================= diff --git a/Lib/idlelib/iomenu.py b/Lib/idlelib/iomenu.py index 464126e2df0668..ea0109e3e4019e 100644 --- a/Lib/idlelib/iomenu.py +++ b/Lib/idlelib/iomenu.py @@ -33,6 +33,8 @@ def __init__(self, editwin): self.save_a_copy) self.fileencoding = 'utf-8' self.__id_print = self.text.bind("<>", self.print_window) + self.__id_copy = self.text.bind("<>", self.copy) + self.__id_cut = self.text.bind("<>", self.cut) def close(self): # Undo command bindings @@ -41,6 +43,8 @@ def close(self): self.text.unbind("<>",self.__id_saveas) self.text.unbind("<>", self.__id_savecopy) self.text.unbind("<>", self.__id_print) + self.text.unbind("<>", self.__id_copy) + self.text.unbind("<>", self.__id_cut) # Break cycles self.editwin = None self.text = None @@ -348,6 +352,20 @@ def print_window(self, event): os.unlink(tempfilename) return "break" + def copy(self, event): + if not self.text.tag_ranges("sel"): + self.text.tag_add("sel", "insert linestart", "insert+1l linestart") + self.text.mark_set("insert", "insert linestart") + self.text.event_generate("<>") + return "break" + + def cut(self, event): + if not self.text.tag_ranges("sel"): + self.text.tag_add("sel", "insert linestart", "insert+1l linestart") + self.text.mark_set("insert", "insert linestart") + self.text.event_generate("<>") + return "break" + opendialog = None savedialog = None diff --git a/Misc/NEWS.d/next/IDLE/2024-10-27-20-17-54.gh-issue-94521.XEFTrz.rst b/Misc/NEWS.d/next/IDLE/2024-10-27-20-17-54.gh-issue-94521.XEFTrz.rst new file mode 100644 index 00000000000000..119f09c69222d7 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2024-10-27-20-17-54.gh-issue-94521.XEFTrz.rst @@ -0,0 +1,2 @@ +If no selection is made during copy/cut, the current line will copy/cut +automatically.