-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
5.1.1 : omitted indentation when pasting with the editor #16159
Comments
Hey @texadactyl, thanks for reporting. I can reproduce this error. @impact27, could you take a look at this? |
The expected behaviour is that it will correct the indentation to where your cursor is. If you add a line below
If you then paste you should get:
If instead you want to de-dent, you should, from:
Press delete:
Then paste:
The new logic tries pastes the code in the clipboard on the indentation your cursor is. |
@impact27, if the first line a user is trying to paste contains some indentation, I think we should preserve it, and adjust the indentation of all other lines according to that. What do you think? |
Folks are used to the spyder editor as it was through 5.0.5. The 5.1.1 editor-paste behaviour will require a lot of users to re-think the way they do copy/cut and paste of large blocks of code. Small segments are no big deal. I do not copy/cut and paste a large block of code spanning multiple lines the way you showed. I'd much rather do a large collection of lines in a line-oriented fashion (cursor on first column). Less chance of a mess. If I need to indent or unindent afterwards, I can plan for that. However, there must be some benefit for this change or you would not have made it. I'll try to figure that out. Not trying to give you a load of re-do. |
What should happen in the case when pasting
I think:
if more helpful than:
But the case in this issue is more debatable. Maybe we could only de-dent if it would result in a non-valid code? |
I think a sound logic would be for pasting to do:
Opened a PR #16164 |
For example, pasting
or:
or:
Pasting
or:
or:
|
@ccordoba12 Do you think this is reasonable? Alternatively we can turn off the point 2 completely. |
This new behaviour also puzzled me and it took me some time to figure out the logic behind it. #16159 (comment) sounds logic to me. There might be another solution, based on my current workflow:
So my suggestion would be to paste them according to any of the two policies but select the pasted lines automatically after pasting. That way you are immediately able to adjust the indentation level after pasting. What do you think? |
The problem with selecting is that if you paste and then write it would remove the lines. The challenge is to do something usefull but try to avoid messing up with the expectations of the user. I don't think the user would expect to have the pasted text selected, even it it could be useful. |
I also just noticed a problem: If you past text inside some existing text, it might not be such a good idea, if it becomes selected. Hence I would like to update my proposal, to select it only, if the selected text contains at least one newline character. Then only blocks would get selected after pasting. Yes, it is impossible to make it right for everyone in every use case!! Alternatively, if that is not an option, a way to select the just-pasted content with a hot key would improve the workflow massively … |
Your users have a variety of habits and concepts of convenience. Cannot please them all. If it were me doing this, I would emphasize safety and consistency. |
Yes, indeed! I believe that @impact27's suggestion is a good solution. If that is not acceptable there is always my suggestion, either with autoselecting the pasted block or adding a keyboard hotkey to select it after pasting, to be able to adjust the indentation quickly (this hotkey can also be added in addition to @impact27's solution and might improve it even further!) |
Yeah, that sounds quite reasonable to me. |
If I apply the changes from 48065f0 (I double checked it) I get this error: Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/spyder/plugins/editor/widgets/codeeditor.py", line 2836, in paste
max_dedent = min(
ValueError: min() arg is an empty sequence What I did?
#!/usr/bin/env python3
"""
Blabla
"""
import sys
import argparse
import ast
try:
import colored_traceback
except ImportError:
pass
else:
colored_traceback.add_hook()
... I positioned the cursor at the start of the line |
I can't reproduce this error. Could you upload an animated gif that shows exactly how to generate it? |
Just in case, I messed something up, I copied this file (https://raw.githubusercontent.com/spyder-ide/spyder/48065f03dc7edb04093425032f9c69f0a26dda25/spyder/plugins/editor/widgets/codeeditor.py) over the existing In the following screencast I use |
I might have an idea, what is going on: The selected text is
(note the empty line at the end).
Finally
True , because len[""] is >0.
But
if line.strip() !=n "" ), hence the list for the call of min() is empty!
|
I solved this by changing the statements between
to indentations = [
self.get_line_indentation(line)
for line in remaining_lines if line.strip() != ""]
if indentations:
max_dedent = min(indentations)
lines_adjustment = max(lines_adjustment, -max_dedent) |
Installed 5.1.1 and reset to factory defaults.
Then, I created a small function:
I wanted to add another assignment just after
x = 1
. So, I copied that entire line and pasted it. This was the result:Uninstalled 5.1.1 and installed 5.0.5. Then, I reset to factory defaults and created the same small function:
Then, I copied that entire
x = 1
line and pasted it. This was the result:IMO, the 5.0.5 editor behaved correctly but the 5.1.1 editor neglected to paste in the indentation.
The text was updated successfully, but these errors were encountered: