From 76f0b9d17b97338a9bdb9a42935b475f106684ce Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 3 Jul 2022 12:00:05 +0800 Subject: [PATCH] - fix: calculation of the code block ranges when inserting/deleting --- NEWS.md | 1 + RedPandaIDE/qsynedit/SynEdit.cpp | 54 +++++++++++++++++--------------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/NEWS.md b/NEWS.md index 071e0219..85b08cb4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ Red Panda C++ Version 1.1.4 - enhancement: only allow insert linebreak at the end of folded code block - enhancement: only allow delete whole folded code block - refactor of undo system + - fix: calculation of the code block ranges when inserting/deleting Red Panda C++ Version 1.1.3 diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index c94f7e61..64f59d93 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -3570,13 +3570,11 @@ void SynEdit::foldOnListInserted(int Line, int Count) // Delete collapsed inside selection for (int i = mAllFoldRanges.count()-1;i>=0;i--) { PSynEditFoldRange range = mAllFoldRanges[i]; - if (range->collapsed || range->parentCollapsed()){ - qDebug()<fromLine<fromLine == Line - 1) // insertion starts at fold line + if (range->fromLine == Line - 1) {// insertion starts at fold line + if (range->collapsed) uncollapse(range); - else if (range->fromLine >= Line) // insertion of count lines above FromLine - range->move(Count); - } + } else if (range->fromLine >= Line) // insertion of count lines above FromLine + range->move(Count); } } @@ -3585,15 +3583,14 @@ void SynEdit::foldOnListDeleted(int Line, int Count) // Delete collapsed inside selection for (int i = mAllFoldRanges.count()-1;i>=0;i--) { PSynEditFoldRange range = mAllFoldRanges[i]; - if (range->collapsed || range->parentCollapsed()){ - qDebug()<fromLine<fromLine == Line && Count == 1) // open up because we are messing with the starting line + if (range->fromLine == Line && Count == 1) {// open up because we are messing with the starting line + if (range->collapsed) uncollapse(range); - else if (range->fromLine >= Line - 1 && range->fromLine < Line + Count) // delete inside affectec area - mAllFoldRanges.remove(i); - else if (range->fromLine >= Line + Count) // Move after affected area - range->move(-Count); - } + } else if (range->fromLine >= Line - 1 && range->fromLine < Line + Count) // delete inside affectec area + mAllFoldRanges.remove(i); + else if (range->fromLine >= Line + Count) // Move after affected area + range->move(-Count); + } } @@ -3616,11 +3613,11 @@ static void null_deleter(SynEditFoldRanges *) {} void SynEdit::rescanForFoldRanges() { // Delete all uncollapsed folds - for (int i=mAllFoldRanges.count()-1;i>=0;i--) { - PSynEditFoldRange range =mAllFoldRanges[i]; - if (!range->collapsed && !range->parentCollapsed()) - mAllFoldRanges.remove(i); - } +// for (int i=mAllFoldRanges.count()-1;i>=0;i--) { +// PSynEditFoldRange range =mAllFoldRanges[i]; +// if (!range->collapsed && !range->parentCollapsed()) +// mAllFoldRanges.remove(i); +// } // Did we leave any collapsed folds and are we viewing a code file? if (mAllFoldRanges.count() > 0) { @@ -3630,21 +3627,26 @@ void SynEdit::rescanForFoldRanges() PSynEditFoldRanges TemporaryAllFoldRanges = std::make_shared(); scanForFoldRanges(TemporaryAllFoldRanges); - + qDebug()<<" ------- "; // Combine new with old folds, preserve parent order for (int i = 0; i< TemporaryAllFoldRanges->count();i++) { + PSynEditFoldRange tempFoldRange=TemporaryAllFoldRanges->range(i); int j=0; while (j range(i)->fromLine<fromLine; - if (TemporaryAllFoldRanges->range(i)->fromLine == ranges[j]->fromLine - && TemporaryAllFoldRanges->range(i)->toLine == ranges[j]->toLine) { - mAllFoldRanges.add(ranges[j]); + PSynEditFoldRange foldRange = ranges[j]; + //qDebug()<range(i)->fromLine<fromLine; + if (tempFoldRange->fromLine == foldRange->fromLine + && tempFoldRange->toLine == foldRange->toLine) { + //qDebug()<<"-"<fromLine; + mAllFoldRanges.add(foldRange); break; } j++; } - if (j>=ranges.count()) - mAllFoldRanges.add(TemporaryAllFoldRanges->range(i)); + if (j>=ranges.count()) { + //qDebug()<<"--"<fromLine; + mAllFoldRanges.add(tempFoldRange); + } } } else {