Texstudio: More consistent indentation when pasting

Created on 16 Apr 2020  路  5Comments  路  Source: texstudio-org/texstudio

I find the behaviour of Texstudio when pasting lines containing indentation very strange. I am spending my time removing/adding indentation. To my opinion, the main point is that Texstudio should not change relative indentation of lines when pasting, at least in the automatic indentation mode.

Let's consider a simple and more complicated example:

  • example 1:
line 1
line 2
    line 3
    line 4
  • example 2:
    \left[
        a
        + 2
            \left(b + c \right)
    \right]

Expected behavior

Pasting on a blank line just gives the same lines, with the same relative indent:

  • example 1 copied on empty line:
line 1
line 2
    line 3
    line 4
  • example 2 copied on empty line, selected from the beginning of the line:
\left[
    a
    + 2
        \left(b + c \right)
\right]
  • example 2 copied on empty line, but selected starting from \left:
    \left[
        a
        + 2
            \left(b + c \right)
    \right]

Copying on a line which is already indented should just preserve the indentation. E.g. with example 1 copied on a line with one tab:

    line 1
    line 2
        line 3
        line 4

Actual behavior

Mode : automatic indentation

Pasting on a blank line just gives:

  • example 1 copied on empty line:
line 1
line 2
line 3
line 4
  • example 2 copied on empty line, selected from the beginning of the line:
    \left[
a
+ 2
\left(b + c \right)
\right]
  • example 2 copied on empty line, but selected starting from \left:
\left[
a
+ 2
\left(b + c \right)
\right]

Pasting on a line with tabs does the same with the same tab inserted in front of all lines, for example:

    line 1
    line 2
    line 3
    line 4

Mode : keep indentation

I find that this mode works a bit better, but there are still problems for my purpose. For example, pasting example 1 works, even on a line with a tab:

    line 1
    line 2
        line 3
        line 4

However, if one considers example 2 and past on a blank line:

\left[
        a
        + 2
            \left(b + c \right)
    \right]

Most helpful comment

@titizaki is right: in all other text editors I tried, copy-pasting with indentation behaves as I would expect. This is why I find the behavior from Texstudio very confusing. There should be a least one option to preserve relative indentation. Another way to say is that it does not try to adapt the indentation in the block pasted beyond the leading tabs which are common to all.

All 5 comments

From the examples above I think that the mode Keep indentation works correctly. It just copies the source text (while preserving all the newlines and tabs verbatim) into the destination at the cursor insertion point. In fact I use this mode while editing documents and I would say that any other behavior would be incorrect/confusing.

The automatic indentation mode also seems correct to me but I will not argue about it since I do not actually use it.

I'd argue that the "keep indentation" behavior for the second example is incorrect because it doesn't preserve the _relative_ indentation: if two elements had the same identation, they should still be that way after pasting.

This is a very common feature in many general-purpose IDE (I do a lot of Python, where this is crucial). If some code had been carefully indented before, the editor should preserve it.

Perhaps a third, "keep relative indentation" option, then? I understand that it might be tricky to implement, because in LaTeX indentations could have varying width. Could it at least work if identations are tabulations, or multiples of xx spaces (with xx being the setting already present in the advanced editor section)?

@titizaki is right: in all other text editors I tried, copy-pasting with indentation behaves as I would expect. This is why I find the behavior from Texstudio very confusing. There should be a least one option to preserve relative indentation. Another way to say is that it does not try to adapt the indentation in the block pasted beyond the leading tabs which are common to all.

In example 2 TeXstudio with autoindentation behaves the same way as Kate, the most popular Linux text editor, which is used both standalone and in many other Linux applications. Anyone using Kate is also used to this behavior.

If anyone wants to provide a patch to change the current behavior, please add a configuration option that would allow keeping the current behavior.

Was this page helpful?
0 / 5 - 0 ratings