From 72d6224f601f638f2df49ff00cb00864bd0d699c Mon Sep 17 00:00:00 2001 From: Wulian Date: Sun, 27 Oct 2024 20:18:47 +0800 Subject: [PATCH 1/4] automati copy/cut --- Doc/whatsnew/3.14.rst | 7 +++++++ Lib/idlelib/News3.txt | 11 ++++++++++- Lib/idlelib/iomenu.py | 19 +++++++++++++++++++ ...4-10-27-20-17-54.gh-issue-94521.XEFTrz.rst | 2 ++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/IDLE/2024-10-27-20-17-54.gh-issue-94521.XEFTrz.rst diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index a6f595ccf08bf4..1c00ab0b4aa586 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -583,6 +583,13 @@ email * Remove the *isdst* parameter from :func:`email.utils.localtime`. (Contributed by Hugo van Kemenade in :gh:`118798`.) +idlelib and IDLE +---------------- + +* While doing copy/cut a empty selection, the current line will be selected + and copied/cut automatically. + (Contributed by Jiahao Li in :gh:`94521`.) + importlib --------- diff --git a/Lib/idlelib/News3.txt b/Lib/idlelib/News3.txt index 37ff93f9866e3c..1af586b037a3f7 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: While doing copy/cut a empty selection, the current line will +be selected and copied/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..103e72d40481a3 100644 --- a/Lib/idlelib/iomenu.py +++ b/Lib/idlelib/iomenu.py @@ -7,6 +7,7 @@ from tkinter import filedialog from tkinter import messagebox +from tkinter import TclError from tkinter.simpledialog import askstring # loadfile encoding. from idlelib.config import idleConf @@ -33,6 +34,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 +44,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 +353,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..ed2b083f424616 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2024-10-27-20-17-54.gh-issue-94521.XEFTrz.rst @@ -0,0 +1,2 @@ +While doing copy/cut a empty selection, the current line will be selected +and copied/cut automatically. From 25bf18f490a9cfe3c9af84806be9e6b959bb2a06 Mon Sep 17 00:00:00 2001 From: Wulian Date: Sun, 27 Oct 2024 20:27:56 +0800 Subject: [PATCH 2/4] news --- Doc/whatsnew/3.14.rst | 4 ++-- Lib/idlelib/News3.txt | 4 ++-- Lib/idlelib/iomenu.py | 1 - .../next/IDLE/2024-10-27-20-17-54.gh-issue-94521.XEFTrz.rst | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 1c00ab0b4aa586..03081d727b1b92 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -586,8 +586,8 @@ email idlelib and IDLE ---------------- -* While doing copy/cut a empty selection, the current line will be selected - and copied/cut automatically. +* If no selection is made during copy/cut, the current line will + copied/cut automatically. (Contributed by Jiahao Li in :gh:`94521`.) importlib diff --git a/Lib/idlelib/News3.txt b/Lib/idlelib/News3.txt index 1af586b037a3f7..bbc06f684a1ad4 100644 --- a/Lib/idlelib/News3.txt +++ b/Lib/idlelib/News3.txt @@ -4,8 +4,8 @@ Released on 2025-10-xx ========================= -gh-94521: While doing copy/cut a empty selection, the current line will -be selected and copied/cut automatically. +gh-94521: If no selection is made during copy/cut, the current line +will copied/cut automatically. What's New in IDLE 3.13.0 (since 3.12.0) diff --git a/Lib/idlelib/iomenu.py b/Lib/idlelib/iomenu.py index 103e72d40481a3..ea0109e3e4019e 100644 --- a/Lib/idlelib/iomenu.py +++ b/Lib/idlelib/iomenu.py @@ -7,7 +7,6 @@ from tkinter import filedialog from tkinter import messagebox -from tkinter import TclError from tkinter.simpledialog import askstring # loadfile encoding. from idlelib.config import idleConf 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 index ed2b083f424616..f4e3cdde7b09e5 100644 --- 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 @@ -1,2 +1,2 @@ -While doing copy/cut a empty selection, the current line will be selected -and copied/cut automatically. +If no selection is made during copy/cut, the current line will copied/cut +automatically. From ff699ca74865900b276a34126141cf65df693df0 Mon Sep 17 00:00:00 2001 From: Wulian Date: Sun, 27 Oct 2024 20:36:49 +0800 Subject: [PATCH 3/4] English grammar correct --- Doc/whatsnew/3.14.rst | 2 +- Lib/idlelib/News3.txt | 2 +- .../next/IDLE/2024-10-27-20-17-54.gh-issue-94521.XEFTrz.rst | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 03081d727b1b92..05f8b41fc444ee 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -587,7 +587,7 @@ idlelib and IDLE ---------------- * If no selection is made during copy/cut, the current line will - copied/cut automatically. + copy/cut automatically. (Contributed by Jiahao Li in :gh:`94521`.) importlib diff --git a/Lib/idlelib/News3.txt b/Lib/idlelib/News3.txt index bbc06f684a1ad4..697233255b5e66 100644 --- a/Lib/idlelib/News3.txt +++ b/Lib/idlelib/News3.txt @@ -5,7 +5,7 @@ Released on 2025-10-xx gh-94521: If no selection is made during copy/cut, the current line -will copied/cut automatically. +will copy/cut automatically. What's New in IDLE 3.13.0 (since 3.12.0) 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 index f4e3cdde7b09e5..119f09c69222d7 100644 --- 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 @@ -1,2 +1,2 @@ -If no selection is made during copy/cut, the current line will copied/cut +If no selection is made during copy/cut, the current line will copy/cut automatically. From 74d82caa33c9d710d92e88ba22efddd67d6fdf74 Mon Sep 17 00:00:00 2001 From: Wulian Date: Mon, 28 Oct 2024 19:52:53 +0800 Subject: [PATCH 4/4] fix --- Doc/whatsnew/3.14.rst | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 05f8b41fc444ee..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 ------- @@ -583,13 +591,6 @@ email * Remove the *isdst* parameter from :func:`email.utils.localtime`. (Contributed by Hugo van Kemenade in :gh:`118798`.) -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`.) - importlib ---------