Open lost-valley opened 5 months ago
Even if this doesn't get implemented, I'd love to hear why this is not a desired behavior :)
I think it's an interesting (and probably useful) behavior, but it probably also cannot be the default. Here are a couple of reasons why from the top of my head:
(current - delta_from_first_line)
? (e.g. aiming for the first line's indent to be the current position's indent, and then adding and removing indentation to match the differences in the pasted content)All that might or might not make sense I guess, depending on the situation. I guess the "best" algorithm is one that takes clipboard indentation deltas into account and applies them, but it's also the most complex and could get things wrong.
As a currently available workaround (which you might already know about), you can easily adjust indentation of a whole series of lines by selecting it and using Tab or Shift+Tab.
And what about pasting Python (or other offside languages)?
Are we pasting:
So just taking deltas into account is still not enough because of 2. vs 3.
Too many choices, but the current behaviour of re-indenting the first line only is likely to be wrong most of the time and probably should be changed for multi-line pastes.
the current behaviour of re-indenting the first line only is likely to be wrong most of the time and probably should be changed for multi-line pastes.
The current behavior does not indent anything, it just insert whatever there is in the clipboard wherever the caret is at. If the caret was at an indentation, so be it. Again, IMO that s must still be available and likely default, because it's the simplest thing to do, and is 100% predictable.
The current behavior does not indent anything
What I mean is that the usual use case is to type return to get a new line to paste on, but that indents with the usual settings for Python, so extra indent is added to the first line unless the user does return then backspaces to remove the indent to start of line and then inserts. Perhaps "re-indent" is the wrong term but the default result is to add indent to the first line of the paste.
Again, IMO that s must still be available and likely default, because it's the simplest thing to do, and is 100% predictable.
Sure I am not suggesting remove it, its is likely the right thing for pastes anywhere besides first on line, just that it isn't the right thing for whole lines with usual settings for offside languages, so that makes more choice and its not really a setting, it will vary from one paste to the next so we need multiple paste options:
Options 2 and 3 should be added to the menu by the language specific plugin that controls behaviour ... what? ... Nooooo!!!
There is a reason nearly all other IDEs are built from plugins, not built-in :grin:
it probably also cannot be the default
Agree
What if the clipboard already has indentation for the subsequent lines? ...
Good point, nice dissection of the problem.
I would go with a rather simplistic algo, that IMO covers a lot of cases without trying to be too smart:
During pasting,
if text before cursor is only whitespace then:
- If every clipboard line has non-zero indentation,
then strip it until any line becomes "unindented"; ignore empty lines
- unless "preserve_source_indentation" is set to "yes" - then don't strip anything
- Prefix every clipboard line with the current_line's indenation level
In pseudo code:
IF current_line.text_before_cursor IS whitespace THEN
IF EVERY clipboard.lines STARTS_WITH whitespace THEN
IF preferences.preserve_source_indentation == false THEN
strip_indentation(clipboard)
END IF
END IF
FOREACH line IN clipboard.lines
line = current_line.text_before_cursor + line
END FOREACH
END IF
Edit: fixed pseudo code algo
Hi, let me start with an expression of gratitude for this great text editor!
This is a feature request:
Scenario steps:
Current behavior: The first line of the text is pasted at the cursor location. (indented on level 2) All the other lines of the clipboard contents are pasted at column 0 (indentation level 1).
Desired behavior: Have all the lines of the pasted clipboard text be "padded" with the indentation level of the cursor.
e.g.
Thanks in advance! Even if this doesn't get implemented, I'd love to hear why this is not a desired behavior :)