Skip to content

gh-94521: IDLE: Auto-select and copy/cut current line if no selection on copy/cut #126034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Expand Down
11 changes: 10 additions & 1 deletion Lib/idlelib/News3.txt
Original file line number Diff line number Diff line change
@@ -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
=========================


Expand Down
18 changes: 18 additions & 0 deletions Lib/idlelib/iomenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def __init__(self, editwin):
self.save_a_copy)
self.fileencoding = 'utf-8'
self.__id_print = self.text.bind("<<print-window>>", self.print_window)
self.__id_copy = self.text.bind("<<copy>>", self.copy)
self.__id_cut = self.text.bind("<<cut>>", self.cut)

def close(self):
# Undo command bindings
Expand All @@ -41,6 +43,8 @@ def close(self):
self.text.unbind("<<save-window-as-file>>",self.__id_saveas)
self.text.unbind("<<save-copy-of-window-as-file>>", self.__id_savecopy)
self.text.unbind("<<print-window>>", self.__id_print)
self.text.unbind("<<copy>>", self.__id_copy)
self.text.unbind("<<cut>>", self.__id_cut)
# Break cycles
self.editwin = None
self.text = None
Expand Down Expand Up @@ -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("<<Copy>>")
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("<<Cut>>")
return "break"

opendialog = None
savedialog = None

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
If no selection is made during copy/cut, the current line will copy/cut
automatically.
Loading