texstudio-org / texstudio-org/texstudio
Pasting code into listings removes indentation
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 403
- Avg merge
- 3h 14m
- Merged PRs (30d)
- 12
Description
By default, you lose all indentation if you copy and past a code listing into a .tex file in TeXStudio. I found the way around this problem, set a config file option: https://sourceforge.net/p/texstudio/bugs/1209/
My suggestion is that, for code at least, maintaining the indentation should be the default. I can imagine that you want to autoindent other latex elements, but for computer source code I think the most common case is that pasting code should maintain the indentation. You could add yet another checkbox for "maintain indentation in code," on by default. I suspect this idea will be shot down, but I hope you consider more creative solutions (maybe a pop up when you first paste a code listing into a window?) - right now TeXStudio looks broken with this "remove code indentation" default in place.
See reproduction steps at bottom.
Environment
- TeXstudio: 2.12.14
- Qt: 5.8.0
- OS: Windows 10
- TeX distribution: miktex
Expected behavior
\begin{lstlisting}[
caption={This short example function illustrates the copy and paste problem}
language=someCode
]
static some_func() {
// indented code - when pasted into TeXStudio, indentation goes away.
float sqrt2 = sqrt(2.0f);
float radperdeg = M_PI / 180.f;
return;
}
\end{lstlisting}
Actual behavior
\begin{lstlisting}[
caption={This short example function illustrates the copy and paste problem}
language=someCode
]
static some_func() {
// indented code - when pasted into TeXStudio, indentation goes away.
float sqrt2 = sqrt(2.0f);
float radperdeg = M_PI / 180.f;
return;
}
\end{lstlisting}
How to reproduce
Take the lines below and copy them. Paste into TeXStudio. The indentation disappears.
\begin{lstlisting}[
caption={This short example function illustrates the copy and paste problem}
language=someCode
]
static some_func() {
// indented code - when pasted into TeXStudio, indentation goes away.
float sqrt2 = sqrt(2.0f);
float radperdeg = M_PI / 180.f;
return;
}
\end{lstlisting}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by following the reproduction steps in the issue using the provided code listing in TeXstudio on the described environment. The work is done when pasted code preserves its indentation by default, with the resulting behavior verified against the expected and actual examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- latex
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100