[QScintilla] text(line) trims the first character for CR+LF files
Manuel Gómez
mgrojo at gmail.com
Mon Nov 19 22:41:40 GMT 2018
Sorry, the problem isn't in text(line) but how is the replacement done.
I thought it was text the one trimming a character, because the debug
traced showed trimmed lines. But I see now that the first line is the
only one being complete. So the problem lies in replaceSelectedText.
This is my code. Its duty is to comment or uncomment a block of SQL code.
int lineFrom, indexFrom, lineTo, indexTo;
// If there is no selection, select the current line
if (!hasSelectedText()) {
getCursorPosition(&lineFrom, &indexFrom);
setSelection(lineFrom, 0, lineFrom, lineLength(lineFrom));
}
getSelection(&lineFrom, &indexFrom, &lineTo, &indexTo);
bool uncomment = text(lineFrom).contains(QRegExp("^[ \t]*--"));
// Iterate over the selected lines, get line text, make
// replacement depending on whether the first line was commented
// or uncommented, and replace the line text.
for (int line=lineFrom; line<lineTo; line++) {
QString lineText = text(line);
qDebug() << lineText;
if (uncomment)
lineText.replace(QRegExp("^([ \t]*)-- ?"), "\\1");
else
lineText.replace(QRegExp("^"), "-- ");
setSelection(line, 0, line, lineLength(line));
replaceSelectedText(lineText);
}
Manuel
El 19/11/18 a las 11:39, Phil Thompson escribió:
> On 18 Nov 2018, at 3:55 pm, Manuel Gómez <mgrojo at gmail.com> wrote:
>>
>> Hi,
>>
>> I just noticed that text(line) is leaving out the first character for a Windows file (CR+LF convention) while is working good for a Linux file (LF convention). The problem is present both under Linux and under Windows, provided that the file follows Windows convention.
>>
>> I'm using version 2.10.8.
>
> I can't reproduce this. Can you give me more details.
>
> Phil
>
More information about the QScintilla
mailing list