- fix: index of the longest line not correctly updated when insert/delete multiple lines ( which will cause selection errors)

This commit is contained in:
Roy Qu 2022-04-24 09:50:30 +08:00
parent 1a7322f562
commit d9259fb9e4
3 changed files with 14 additions and 8 deletions

View File

@ -10,6 +10,7 @@ Red Panda C++ Version 1.0.5
- enhancement: only show function tips when cursor is after ',' or '('. - enhancement: only show function tips when cursor is after ',' or '('.
- enhancement: when auto complete function names, only append '(' if before identifier or "/' - enhancement: when auto complete function names, only append '(' if before identifier or "/'
- update highconstrast icon set - update highconstrast icon set
- fix: index of the longest line not correctly updated when insert/delete multiple lines ( which will cause selection errors)
Red Panda C++ Version 1.0.4 Red Panda C++ Version 1.0.4
- fix: hide function tips, when move or resize the main window - fix: hide function tips, when move or resize the main window

View File

@ -3482,7 +3482,6 @@ void Editor::updateFunctionTip(bool showTip)
if (currentLine>=document()->count()) if (currentLine>=document()->count())
return; return;
QChar ch=lastNonSpaceChar(currentLine,currentChar); QChar ch=lastNonSpaceChar(currentLine,currentChar);
qDebug()<<ch;
if (ch!="(" && ch!=",") if (ch!="(" && ch!=",")
return; return;

View File

@ -348,8 +348,12 @@ void SynDocument::deleteLines(int Index, int NumLines)
auto action = finally([this]{ auto action = finally([this]{
endUpdate(); endUpdate();
}); });
if (mIndexOfLongestLine>=Index && (mIndexOfLongestLine <Index+NumLines)) { if (mIndexOfLongestLine>=Index) {
mIndexOfLongestLine = - 1; if (mIndexOfLongestLine <Index+NumLines) {
mIndexOfLongestLine = -1;
} else {
mIndexOfLongestLine -= NumLines;
}
} }
int LinesAfter = mLines.count() - (Index + NumLines); int LinesAfter = mLines.count() - (Index + NumLines);
if (LinesAfter < 0) { if (LinesAfter < 0) {
@ -482,6 +486,7 @@ void SynDocument::insertLines(int Index, int NumLines)
auto action = finally([this]{ auto action = finally([this]{
endUpdate(); endUpdate();
}); });
mIndexOfLongestLine = -1;
PSynDocumentLine line; PSynDocumentLine line;
mLines.insert(Index,NumLines,line); mLines.insert(Index,NumLines,line);
for (int i=Index;i<Index+NumLines;i++) { for (int i=Index;i<Index+NumLines;i++) {
@ -503,6 +508,7 @@ void SynDocument::insertStrings(int Index, const QStringList &NewStrings)
auto action = finally([this]{ auto action = finally([this]{
endUpdate(); endUpdate();
}); });
mIndexOfLongestLine = -1;
PSynDocumentLine line; PSynDocumentLine line;
mLines.insert(Index,NewStrings.length(),line); mLines.insert(Index,NewStrings.length(),line);
for (int i=0;i<NewStrings.length();i++) { for (int i=0;i<NewStrings.length();i++) {
@ -579,9 +585,13 @@ void SynDocument::loadFromFile(const QString& filename, const QByteArray& encodi
if (!file.open(QFile::ReadOnly )) if (!file.open(QFile::ReadOnly ))
throw FileError(tr("Can't open file '%1' for read!").arg(file.fileName())); throw FileError(tr("Can't open file '%1' for read!").arg(file.fileName()));
beginUpdate(); beginUpdate();
internalClear();
auto action = finally([this]{ auto action = finally([this]{
if (mLines.count()>0)
emit inserted(0,mLines.count());
endUpdate(); endUpdate();
}); });
mIndexOfLongestLine = -1;
//test for utf8 / utf 8 bom //test for utf8 / utf 8 bom
if (encoding == ENCODING_AUTO_DETECT) { if (encoding == ENCODING_AUTO_DETECT) {
if (file.atEnd()) { if (file.atEnd()) {
@ -636,7 +646,6 @@ void SynDocument::loadFromFile(const QString& filename, const QByteArray& encodi
} }
line = file.readLine(); line = file.readLine();
} }
emit inserted(0,mLines.count());
if (!needReread) { if (!needReread) {
if (allAscii) if (allAscii)
realEncoding = ENCODING_ASCII; realEncoding = ENCODING_ASCII;
@ -646,7 +655,6 @@ void SynDocument::loadFromFile(const QString& filename, const QByteArray& encodi
QList<PCharsetInfo> charsets = pCharsetInfoManager->findCharsetByLocale(pCharsetInfoManager->localeName()); QList<PCharsetInfo> charsets = pCharsetInfoManager->findCharsetByLocale(pCharsetInfoManager->localeName());
if (!charsets.isEmpty()) { if (!charsets.isEmpty()) {
if (tryLoadFileByEncoding(realEncoding,file)) { if (tryLoadFileByEncoding(realEncoding,file)) {
emit inserted(0,mLines.count());
return; return;
} }
@ -659,9 +667,8 @@ void SynDocument::loadFromFile(const QString& filename, const QByteArray& encodi
if (encodingName == ENCODING_UTF8) if (encodingName == ENCODING_UTF8)
continue; continue;
if (tryLoadFileByEncoding(encodingName,file)) { if (tryLoadFileByEncoding(encodingName,file)) {
qDebug()<<encodingName; //qDebug()<<encodingName;
realEncoding = encodingName; realEncoding = encodingName;
emit inserted(0,mLines.count());
return; return;
} }
} }
@ -694,7 +701,6 @@ void SynDocument::loadFromFile(const QString& filename, const QByteArray& encodi
} }
addItem(line); addItem(line);
} }
emit inserted(0,mLines.count());
} }