show "..." instead of "...}" when folding #if/#endif

This commit is contained in:
Roy Qu 2023-02-17 18:29:23 +08:00
parent 4b54d3799a
commit 766bf62c04
1 changed files with 21 additions and 13 deletions

View File

@ -1919,7 +1919,7 @@ void QSynEdit::endEditing()
if (mEditingCount==0) { if (mEditingCount==0) {
if (!mUndoing) if (!mUndoing)
mUndoList->endBlock(); mUndoList->endBlock();
rescanRanges(); reparseDocument();
} }
decPaintLock(); decPaintLock();
} }
@ -3354,7 +3354,7 @@ void QSynEdit::scanFrom(int index)
return ; return ;
} }
void QSynEdit::rescanRange(int line) void QSynEdit::reparseLine(int line)
{ {
if (!mSyntaxer) if (!mSyntaxer)
return; return;
@ -3374,7 +3374,7 @@ void QSynEdit::rescanRange(int line)
mDocument->setSyntaxState(line,iRange); mDocument->setSyntaxState(line,iRange);
} }
void QSynEdit::rescanRanges() void QSynEdit::reparseDocument()
{ {
if (mSyntaxer && !mDocument->empty()) { if (mSyntaxer && !mDocument->empty()) {
mSyntaxer->resetState(); mSyntaxer->resetState();
@ -3458,6 +3458,7 @@ void QSynEdit::foldOnListCleared()
void QSynEdit::rescanFolds() void QSynEdit::rescanFolds()
{ {
//qDebug()<<QDateTime::currentDateTime();
if (!mUseCodeFolding) if (!mUseCodeFolding)
return; return;
rescanForFoldRanges(); rescanForFoldRanges();
@ -4746,7 +4747,7 @@ void QSynEdit::setSyntaxer(const PSyntaxer &syntaxer)
auto action=finally([this]{ auto action=finally([this]{
mDocument->endUpdate(); mDocument->endUpdate();
}); });
rescanRanges(); reparseDocument();
} }
onSizeOrFontChanged(true); onSizeOrFontChanged(true);
invalidate(); invalidate();
@ -5312,6 +5313,7 @@ void QSynEdit::doDeleteText(BufferCoord startPos, BufferCoord endPos, SelectionM
} }
} }
QStringList deleted=getContent(startPos,endPos,mode); QStringList deleted=getContent(startPos,endPos,mode);
beginEditingWithoutUndo();
switch(mode) { switch(mode) {
case SelectionMode::Normal: case SelectionMode::Normal:
if (mDocument->count() > 0) { if (mDocument->count() > 0) {
@ -5320,18 +5322,11 @@ void QSynEdit::doDeleteText(BufferCoord startPos, BufferCoord endPos, SelectionM
// the selection mark. // the selection mark.
QString TempString = mDocument->getLine(startPos.line - 1).mid(0, startPos.ch - 1) QString TempString = mDocument->getLine(startPos.line - 1).mid(0, startPos.ch - 1)
+ mDocument->getLine(endPos.line - 1).mid(endPos.ch-1); + mDocument->getLine(endPos.line - 1).mid(endPos.ch-1);
// bool collapsed=foldCollapsedBetween(BB.Line,BE.Line);
// Delete all lines in the selection range. // Delete all lines in the selection range.
mDocument->deleteLines(startPos.line, endPos.line - startPos.line); mDocument->deleteLines(startPos.line, endPos.line - startPos.line);
properSetLine(startPos.line-1,TempString); properSetLine(startPos.line-1,TempString);
UpdateMarks = true; UpdateMarks = true;
internalSetCaretXY(startPos); internalSetCaretXY(startPos);
// if (collapsed) {
// PSynEditFoldRange foldRange = foldStartAtLine(BB.Line);
// if (!foldRange
// || (!foldRange->collapsed))
// uncollapseAroundLine(BB.Line);
// }
} }
break; break;
case SelectionMode::Column: case SelectionMode::Column:
@ -5378,6 +5373,7 @@ void QSynEdit::doDeleteText(BufferCoord startPos, BufferCoord endPos, SelectionM
// Update marks // Update marks
if (UpdateMarks) if (UpdateMarks)
doLinesDeleted(startPos.line, endPos.line - startPos.line + MarkOffset); doLinesDeleted(startPos.line, endPos.line - startPos.line + MarkOffset);
endEditingWithoutUndo();
if (!mUndoing) { if (!mUndoing) {
mUndoList->addChange(ChangeReason::Delete, mUndoList->addChange(ChangeReason::Delete,
startPos, startPos,
@ -5478,7 +5474,7 @@ int QSynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList
str = sLeftSide + text[0] + sRightSide; str = sLeftSide + text[0] + sRightSide;
properSetLine(caretY - 1, str); properSetLine(caretY - 1, str);
} }
rescanRange(caretY); reparseLine(caretY);
// step2: insert remaining lines of Value // step2: insert remaining lines of Value
for (int i=1;i<text.length();i++) { for (int i=1;i<text.length();i++) {
bool notInComment = true; bool notInComment = true;
@ -5510,7 +5506,7 @@ int QSynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList
} }
} }
properSetLine(caretY - 1, str,false); properSetLine(caretY - 1, str,false);
rescanRange(caretY); reparseLine(caretY);
result++; result++;
} }
bChangeScroll = !mOptions.testFlag(eoScrollPastEol); bChangeScroll = !mOptions.testFlag(eoScrollPastEol);
@ -5952,6 +5948,18 @@ void QSynEdit::onBeginFirstPaintLock()
} }
void QSynEdit::beginEditingWithoutUndo()
{
mEditingCount++;
}
void QSynEdit::endEditingWithoutUndo()
{
mEditingCount--;
if (mEditingCount==0)
reparseDocument();
}
bool QSynEdit::isIdentChar(const QChar &ch) bool QSynEdit::isIdentChar(const QChar &ch)
{ {
if (mSyntaxer) { if (mSyntaxer) {