Environment completion: only insert newline when necessary
This change makes a newline to be inserted after \end{env} only if there
was text to
the right of the cursor when the user pressed enter. It also makes sure
the newline respects the existing indentation.
The special case of \[...\]
is also handled.
BUG: 177611
Test cases:
In each case below, the pipe character is meant to denote the position of the cursor, not an actual character. Place the cursor as indicated (in insert mode) and press the Enter key on the keyboard.
1. Before pressing Enter:
\begin{equation}|
After pressing Enter:
\begin{equation}
|
\end{equation}
2. Before pressing Enter:
\begin{align}
\begin{split}|
\end{align}
After pressing Enter:
\begin{align}
\begin{split}
|
\end{split}
\end{align}
3. Before pressing Enter:
\begin{equation}|abc123
After pressing Enter:
\begin{equation}
|
\end{equation}
abc123
4. Before pressing Enter:
\begin{align}
\begin{split}|abc123
\end{align}
After pressing Enter:
\begin{align}
\begin{split}
|
\end{split}
abc123
\end{align}
5. Before pressing Enter:
\[|abcasdf
After pressing Enter:
\[
|
\]
abcasdf