Skip to content

gh-94521: Copy or cut current line while no selection - #145134

Open
znsoooo wants to merge 6 commits into
python:mainfrom
znsoooo:dev-copy-current-line-when-no-select
Open

znsoooo wants to merge 6 commits into
python:mainfrom
znsoooo:dev-copy-current-line-when-no-select

Conversation

@znsoooo

@znsoooo znsoooo commented Feb 23, 2026 •

Copy link
Copy Markdown
Contributor

When the selection is empty, pressing Ctrl-C/Ctrl-X would copy text of zero length, which seems make no sense, and probably cause mistakes (e.g. forgot copy a zero-length text). Therefore, I modified the behavior to copy the current line when there is no selection, which supported by some other editors.

Comment thread Misc/NEWS.d/next/IDLE/2026-02-23-17-28-34.gh-issue-94521.vlr8XB.rst
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 7, 2026
Comment thread Lib/idlelib/editor.py Outdated

def cut(self,event):
if not self.text.tag_ranges('sel'):
self.text.tag_add('sel', 'insert linestart', 'insert+1l linestart')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work with multiple empty lines between 2 meaningful lines?
[and same comment for the copy action]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the cursor is on an empty line, after my patch, pressing Ctrl-C will copy this empty line, so it is '\n'.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jun 23, 2026

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Moving the cursor to the start of the line is right (Ctrl-C Ctrl-V then duplicates the line), but the line must not be selected: after this patch the next typed character replaces the whole line. Put the line on the clipboard directly instead of selecting it: text.clipboard_clear(); text.clipboard_append(text.get('insert linestart', 'insert+1line linestart')). For cut, do the same and then delete the line with text.delete().

Please also add a test in idle_test/test_editor.py (clipboard content, no selection, cursor at the line start, line deleted for cut) and update the Cut and Copy entries in Doc/library/idle.rst.

Ctrl-C in the Shell still interrupts, since the interrupt binding runs first when there is no selection.

@bedevere-app

bedevere-app Bot commented Sep 21, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@znsoooo

znsoooo commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka

but the line must not be selected

Why can't this line be selected? After pressing Ctrl-C, the line will be selected and copied. Isn't it more intuitive for users to know that the copied part is the selected line?

This is just my opinion, and I wanted to discuss it with you.

I’ll complete the test case after a while.

@serhiy-storchaka

Copy link
Copy Markdown
Member

If it remains selected after copying, then pressing any character key will remove it. Pressing Ctrl-V will replace it with itself, which is less useful than duplicating.

@terryjreedy

Copy link
Copy Markdown
Member

I may not accept the issue, but have spent my time on many other issues.

@znsoooo
znsoooo force-pushed the dev-copy-current-line-when-no-select branch from 17db7cd to b930b29 Compare October 7, 2026 14:45
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 7, 2026
@znsoooo

znsoooo commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka I have made the requested changes; please review again

@bedevere-app

bedevere-app Bot commented Oct 8, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@serhiy-storchaka: please review the changes made to this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting change review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants