Skip to content

Commit 72d6224

Browse files
committed
automati copy/cut
1 parent dc76a4a commit 72d6224

4 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎Doc/whatsnew/3.14.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,13 @@ email
583583
* Remove the *isdst* parameter from :func:`email.utils.localtime`.
584584
(Contributed by Hugo van Kemenade in :gh:`118798`.)
585585

586+
idlelib and IDLE
587+
----------------
588+
589+
* While doing copy/cut a empty selection, the current line will be selected
590+
and copied/cut automatically.
591+
(Contributed by Jiahao Li in :gh:`94521`.)
592+
586593
importlib
587594
---------
588595

‎Lib/idlelib/News3.txt‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
What's New in IDLE 3.14.0
2+
(since 3.13.0)
3+
Released on 2025-10-xx
4+
=========================
5+
6+
7+
gh-94521: While doing copy/cut a empty selection, the current line will
8+
be selected and copied/cut automatically.
9+
110
What's New in IDLE 3.13.0
211
(since 3.12.0)
3-
Released on 2024-10-xx
12+
Released on 2024-10-07
413
=========================
514

615

‎Lib/idlelib/iomenu.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from tkinter import filedialog
99
from tkinter import messagebox
10+
from tkinter import TclError
1011
from tkinter.simpledialog import askstring # loadfile encoding.
1112

1213
from idlelib.config import idleConf
@@ -33,6 +34,8 @@ def __init__(self, editwin):
3334
self.save_a_copy)
3435
self.fileencoding = 'utf-8'
3536
self.__id_print = self.text.bind("<<print-window>>", self.print_window)
37+
self.__id_copy = self.text.bind("<<copy>>", self.copy)
38+
self.__id_cut = self.text.bind("<<cut>>", self.cut)
3639

3740
def close(self):
3841
# Undo command bindings
@@ -41,6 +44,8 @@ def close(self):
4144
self.text.unbind("<<save-window-as-file>>",self.__id_saveas)
4245
self.text.unbind("<<save-copy-of-window-as-file>>", self.__id_savecopy)
4346
self.text.unbind("<<print-window>>", self.__id_print)
47+
self.text.unbind("<<copy>>", self.__id_copy)
48+
self.text.unbind("<<cut>>", self.__id_cut)
4449
# Break cycles
4550
self.editwin = None
4651
self.text = None
@@ -348,6 +353,20 @@ def print_window(self, event):
348353
os.unlink(tempfilename)
349354
return "break"
350355

356+
def copy(self, event):
357+
if not self.text.tag_ranges("sel"):
358+
self.text.tag_add("sel", "insert linestart", "insert+1l linestart")
359+
self.text.mark_set("insert", "insert linestart")
360+
self.text.event_generate("<<Copy>>")
361+
return "break"
362+
363+
def cut(self, event):
364+
if not self.text.tag_ranges("sel"):
365+
self.text.tag_add("sel", "insert linestart", "insert+1l linestart")
366+
self.text.mark_set("insert", "insert linestart")
367+
self.text.event_generate("<<Cut>>")
368+
return "break"
369+
351370
opendialog = None
352371
savedialog = None
353372

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
While doing copy/cut a empty selection, the current line will be selected
2+
and copied/cut automatically.

0 commit comments

Comments
 (0)