Skip to content
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

Request: copy entire line with CTRL+C and no selection #21264

Closed
rlabbe opened this issue Aug 16, 2023 · 12 comments · Fixed by #22480
Closed

Request: copy entire line with CTRL+C and no selection #21264

rlabbe opened this issue Aug 16, 2023 · 12 comments · Fixed by #22480

Comments

@rlabbe
Copy link

rlabbe commented Aug 16, 2023

Many code editors, such as Visual Studio Code, Sublime Text, any JetBrain IDE, etc, will copy an entire line of code if you press Ctrl+C with the cursor on a line but nothing selected. I find this very useful and use it all the time. It would be nice to have this in Spyder, perhaps as a settable preference in Preferences/Editor, not the least because it is in muscle memory and I keep trying to do it over and over!

@dalthviz
Copy link
Member

Hi @rlabbe thank you for the feedback! Seems like a reasonable feature to me 👍 Checking a little bit seems like the implementation of such a feature would be related with the following method:

def copy(self):
"""
Reimplement Qt method
Copy text to clipboard with correct EOL chars
"""
if self.get_selected_text():
QApplication.clipboard().setText(self.get_selected_text())

Also, what do you think about the feature @spyder-ide/core-developers ?

@ccordoba12
Copy link
Member

It seems reasonable to me and not so hard to implement. So I'd say we should do it.

@ccordoba12 ccordoba12 added this to the v6.0alphaX milestone Aug 17, 2023
@jitseniesen
Copy link
Member

I like it, maybe we can do the same with CTRL+X? Though that seems to be implemented differently.

@dalthviz
Copy link
Member

In case of the cut functionality I think the change will need to be done at

@Slot()
def cut(self):
"""Reimplement cut to signal listeners about changes on the text."""
has_selected_text = self.has_selected_text()
if not has_selected_text:
return
start, end = self.get_selection_start_end()
self.sig_will_remove_selection.emit(start, end)
TextEditBaseWidget.cut(self)
self._save_clipboard_indentation()
self.sig_text_was_inserted.emit()

Checking seems like VSCode offers that functionality so it could be nice to have it 👍

@ccordoba12
Copy link
Member

Checking seems like VSCode offers that functionality so it could be nice to have it 👍

How does it work in VSCode?

@dalthviz
Copy link
Member

Same principle I would say. If you don't have a selection, the current line under the cursor gets cut (it's removed and put in the clipboard):

cut

@ccordoba12 ccordoba12 modified the milestones: v6.0alphaX, v6.0alpha3 Aug 21, 2023
@ccordoba12 ccordoba12 modified the milestones: v6.0alpha3, v6.0beta1 Nov 17, 2023
@ccordoba12 ccordoba12 modified the milestones: v6.0alpha4, v6.0beta1 Feb 6, 2024
@ccordoba12 ccordoba12 modified the milestones: v6.0alpha5, v6.1.0 Mar 12, 2024
@The-Ludwig
Copy link
Contributor

Hello! Is there already a PR for this feature?
I am REALLY interested in this feature! :)

@ccordoba12
Copy link
Member

No, we haven't had time to work on it, sorry.

@dalthviz dalthviz removed their assignment Sep 6, 2024
@dalthviz
Copy link
Member

dalthviz commented Sep 6, 2024

Would you like to help implementing it @The-Ludwig ?

@The-Ludwig
Copy link
Contributor

@dalthviz, yes very much so! If somebody gives me a hint at where to start (I already see some suggestions in this thread), I am happy to get started on this!

@The-Ludwig
Copy link
Contributor

@ccordoba12 @dalthviz
I got it working! Thanks for tipping me off to the right files!
PR is #22480.

I have to say I was pleasantly surprised how easy it was to get a whole dev-setup for spyder to work, congrats for this level of maintainability!

The PR mimics the behaviour of e.g. VSCode almost perfectly, except when it comes to pasting the copied/cut line again into the editor. There we need to modify CodeEditor.paste, which is a bit over my level of understanding this codebase.
The problem basically is, that we need to remember if the current clipboard was cut/copied with no selection, and if so, then we always insert the content on the line above (as opposed to at the current cursor position, which could be the middle of the line). Further discussion over at the #22480 ?

@dalthviz
Copy link
Member

dalthviz commented Sep 16, 2024

Awesome! Thank you @The-Ludwig for working on this! And yep, I think we can further discuss details and possible follow up work over #22480 👍

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

Successfully merging a pull request may close this issue.

5 participants