Adapt to QScintilla behaviour with Windows line terminator

QScintilla is returning strings with text(line) with line terminator and
they are also counted by lineLength, so the Windows version has to
substract one for setSelection.

This solves various problems resulting in characters being removed at the
beginning of lines when commenting or uncommenting blocks of code with
Windows line terminators.
This commit is contained in:
mgrojo
2018-11-20 00:15:58 +01:00
parent df3a1b1188
commit 70534e2ae3

View File

@@ -104,12 +104,15 @@ void SqlTextEdit::toggleBlockComment()
// or uncommented, and replace the line text.
for (int line=lineFrom; line<lineTo; line++) {
QString lineText = text(line);
if (uncomment)
lineText.replace(QRegExp("^([ \t]*)-- ?"), "\\1");
else
lineText.replace(QRegExp("^"), "-- ");
setSelection(line, 0, line, lineLength(line));
indexTo = lineText.endsWith("\r\n") ? lineLength(line)-1 : lineLength(line);
setSelection(line, 0, line, indexTo);
replaceSelectedText(lineText);
}
}