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

Do not "keep indentation" when pasting #1344

Open
schtandard opened this issue Nov 5, 2020 · 8 comments
Open

Do not "keep indentation" when pasting #1344

schtandard opened this issue Nov 5, 2020 · 8 comments

Comments

@schtandard
Copy link
Contributor

schtandard commented Nov 5, 2020

When selecting text and pressing Ctrl + X, Ctrl + V (i.e. cut and paste), I would expect the end result to be the same as when I started. However TeXstudio does not do this in very common situations, namely when newlines are contained in the pasted text and it is pasted on an indented line.

I should clarify that I am working with the "Keep Indentation" setting. This does not apply to the "Ignore Indentation" setting (as it does not occur there) or the "Indent and Unindent Automatically" setting (as automatic indentation is explicitly requested there).

The Situation

Ok, so let's look at an example.

The following lines are indented.
  This is an indented line.
  Here is another line like before.

Let's say I select everything from the end of the second to the end of the third line (either using the mouse or by putting the cursor at the end of the third line and pressing Shift + Up) and press Ctrl + X, Ctrl + V. The third line is pasted with double indentation (because the copied indentation is added to the one on the second line, where it is pasted). If I press Ctrl + V a couple of times more, each line is indented further than the last. We end up with the following.

The following lines are indented.
  This is an indented line.
    Here is another line like before.
      Here is another line like before.
        Here is another line like before.
          Here is another line like before.

(If one copies the text (Ctrl + C) insted of cutting, all the pasted lines will be indented 2 spaces fewer, because the selection is still active then pasting for the first time.)

While cutting and pasting lines of code in the same place is rarely useful, cutting it in one place and pasting it at another is a common operation, as is copying some lines and pasting them multiple times. With the current behavior, one has to either unindent the code before cutting/copying or fix the indentation after pasting, both of which is rather tedious. Furthermore, this behavior is rather surprising and confusing (I have never seen it in another text editor and even after years of using TeXstudio I still trip up over this).

The Remedy

I can think of two ways to tackle this problem

  1. One could simply not add the indentation of the current line to each pasted line, i.e. only insert the indentation that was actually copied. For me, this would be the desired behavior in the vast majority of cases. The only time it is not, is when moving code from one level of indentation to another. However, even then this behavior is simple and predictable and having to adjust indentation in such a case seems rather intuitive. (Actually, one usually has to do that with the current behavior, too: Copying lines of code indented by 1 unit and pasting them on a line indented by 2 units will indent the pasted lines by 3 units, not 2.)

  2. One could remember the indentation of the line the code was copied from and try to calculate the "correct" indentation when pasting. This seems rather difficult, though, and couldn't work when pasting text from external applications, which is why I would prefer the first option.

@sunderme
Copy link
Member

sunderme commented Nov 7, 2020

I can't reproduce that behaviour, looks okay here.

So maybe start with the basics and provide all the info the template already asked ? (OS;versions etc)

@schtandard
Copy link
Contributor Author

Ok, sorry, I assumed that this was by design..

Environment

  • TeXstudio: 3.0.1
  • Qt: 5.12.1
  • OS: Windows 10
  • TeX distribution: MiKTeX (but also tested with TeX Live)

@schtandard
Copy link
Contributor Author

Note that has been the behavior on Windows for as long as I can remember. So, if it's an environment specific thing, the OS should be the only thing that matters.

@sunderme
Copy link
Member

sunderme commented Nov 7, 2020

I don‘t see that behaviour on windows either
please upload your texstudio.ini

@schtandard
Copy link
Contributor Author

Hmm weird. You do have "Keep Indentation" selected, right?

Here's my texstudio.ini.

@sunderme
Copy link
Member

sunderme commented Nov 7, 2020

works as expected with your texstudio.ini

@schtandard
Copy link
Contributor Author

Just to make sure that we're doing the same thing, here's what I'm doing.

texstudio

@sunderme
Copy link
Member

sunderme commented Nov 7, 2020

okay, now I see

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

No branches or pull requests

2 participants