- fix: index out of range in cpp highlighter

- fix: memory leak in code folding processing
This commit is contained in:
Roy Qu 2022-10-19 22:54:08 +08:00
parent fc8e37d55e
commit 98f4766ffd
4 changed files with 18 additions and 21 deletions

View File

@ -29,6 +29,8 @@ Red Panda C++ Version 1.5
- fix: ctrl+click on #include_next header name doesn't open the right file - fix: ctrl+click on #include_next header name doesn't open the right file
- enhancement: parser used for non-project C files won't search header files in C++ include folders. - enhancement: parser used for non-project C files won't search header files in C++ include folders.
- fix: toggle block comment/delete to word begin/delete to word end are not correctly disabled when editor not open - fix: toggle block comment/delete to word begin/delete to word end are not correctly disabled when editor not open
- fix: index out of range in cpp highlighter
- fix: memory leak in code folding processing
Red Panda C++ Version 1.4 Red Panda C++ Version 1.4

View File

@ -72,16 +72,15 @@ void CodeFoldingRange::move(int count)
toLine += count; toLine += count;
} }
CodeFoldingRange::CodeFoldingRange(PCodeFoldingRange aParent, CodeFoldingRange::CodeFoldingRange(PCodeFoldingRange parent,
int aFromLine, int fromLine,
PCodeFoldingDefine aFoldRegion, int aToLine): int toLine):
fromLine(aFromLine), fromLine(fromLine),
toLine(aToLine), toLine(toLine),
linesCollapsed(0), linesCollapsed(0),
collapsed(false), collapsed(false),
foldRegion(aFoldRegion),
hintMarkLeft(0), hintMarkLeft(0),
parent(aParent) parent(parent)
{ {
subFoldRanges = std::make_shared<CodeFoldingRanges>(); subFoldRanges = std::make_shared<CodeFoldingRanges>();
} }
@ -107,16 +106,15 @@ CodeFoldingRanges::CodeFoldingRanges()
} }
PCodeFoldingRange CodeFoldingRanges::addByParts(PCodeFoldingRange aParent, PCodeFoldingRange CodeFoldingRanges::addByParts(PCodeFoldingRange parent,
PCodeFoldingRanges aAllFold, PCodeFoldingRanges allFold,
int aFromLine, int fromLine,
PCodeFoldingDefine aFoldRegion, int toLine)
int aToLine)
{ {
PCodeFoldingRange range=std::make_shared<CodeFoldingRange>(aParent, aFromLine,aFoldRegion,aToLine); PCodeFoldingRange range=std::make_shared<CodeFoldingRange>(parent, fromLine,toLine);
mRanges.append(range); mRanges.append(range);
if (aAllFold && aAllFold.get()!=this) { if (allFold && allFold.get()!=this) {
aAllFold->add(range); allFold->add(range);
} }
return range; return range;
} }

View File

@ -67,8 +67,8 @@ public:
void clear(); void clear();
int count() const; int count() const;
CodeFoldingRanges(); CodeFoldingRanges();
PCodeFoldingRange addByParts(PCodeFoldingRange aParent, PCodeFoldingRanges aAllFold, PCodeFoldingRange addByParts(PCodeFoldingRange parent, PCodeFoldingRanges allFold,
int aFromLine, PCodeFoldingDefine aFoldRegion, int aToLine); int fromLine, int toLine);
void insert(int index, PCodeFoldingRange range); void insert(int index, PCodeFoldingRange range);
void remove(int index); void remove(int index);
@ -84,12 +84,11 @@ public:
int linesCollapsed; // Number of collapsed lines int linesCollapsed; // Number of collapsed lines
PCodeFoldingRanges subFoldRanges; // Sub fold ranges PCodeFoldingRanges subFoldRanges; // Sub fold ranges
bool collapsed; // Is collapsed? bool collapsed; // Is collapsed?
std::weak_ptr<CodeFoldingDefine> foldRegion; // FoldRegion
int hintMarkLeft; int hintMarkLeft;
std::weak_ptr<CodeFoldingRange> parent; std::weak_ptr<CodeFoldingRange> parent;
bool parentCollapsed(); bool parentCollapsed();
void move(int count); void move(int count);
explicit CodeFoldingRange(PCodeFoldingRange aParent, int aFromLine, PCodeFoldingDefine aFoldRegion, int aToLine); explicit CodeFoldingRange(PCodeFoldingRange parent, int fromLine, int toLine);
}; };
} }

View File

@ -3705,7 +3705,6 @@ void SynEdit::findSubFoldRange(PCodeFoldingRanges TopFoldRanges, int FoldIndex,P
Parent, Parent,
TopFoldRanges, TopFoldRanges,
Line + 1, Line + 1,
mCodeFolding.foldRegions.get(FoldIndex),
Line + 1); Line + 1);
parentFoldRanges = Parent->subFoldRanges; parentFoldRanges = Parent->subFoldRanges;
} }
@ -3734,7 +3733,6 @@ void SynEdit::findSubFoldRange(PCodeFoldingRanges TopFoldRanges, int FoldIndex,P
Parent, Parent,
TopFoldRanges, TopFoldRanges,
Line + 1, Line + 1,
mCodeFolding.foldRegions.get(FoldIndex),
Line + 1); Line + 1);
parentFoldRanges = Parent->subFoldRanges; parentFoldRanges = Parent->subFoldRanges;