Skip to content

Commit 5f365f3

Browse files
committed
Fix crash while folding ranges.
1 parent c394cc4 commit 5f365f3

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

src/eepp/ui/doc/syntaxtokenizer.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,11 @@ _tokenize( const SyntaxDefinition& syntax, const std::string& text, const Syntax
395395
while ( currentBytePos < fullMatchEnd ) {
396396
size_t currentCaptureIndex =
397397
priorityMap[currentBytePos - fullMatchStart];
398-
SyntaxStyleType currentType = SyntaxStyleEmpty();
399-
400-
if ( currentCaptureIndex < pattern.types.size() ) {
401-
currentType = pattern.types[currentCaptureIndex];
402-
} else {
403-
currentType = pattern.types.empty() ? SyntaxStyleTypes::Normal
404-
: pattern.types[0];
405-
}
398+
SyntaxStyleType currentType =
399+
currentCaptureIndex < pattern.types.size()
400+
? pattern.types[currentCaptureIndex]
401+
: ( pattern.types.empty() ? SyntaxStyleTypes::Normal
402+
: pattern.types[0] );
406403

407404
int segmentEndBytePos = currentBytePos + 1;
408405
while ( segmentEndBytePos < fullMatchEnd &&
@@ -416,30 +413,26 @@ _tokenize( const SyntaxDefinition& syntax, const std::string& text, const Syntax
416413

417414
if ( currentType == SyntaxStyleTypes::Symbol ||
418415
currentType == SyntaxStyleTypes::Normal ) {
419-
patternTextStr = segmentText; // Need a std::string for lookup
420-
SyntaxStyleType symbolType =
421-
curState.currentSyntax->getSymbol( patternTextStr );
416+
SyntaxStyleType symbolType = curState.currentSyntax->getSymbol(
417+
( patternTextStr = segmentText ) );
422418
if ( symbolType != SyntaxStyleEmpty() ) {
423419
currentType = symbolType;
424420
} else if ( currentType == SyntaxStyleTypes::Symbol ) {
425421
currentType = SyntaxStyleTypes::Normal;
426422
}
427423
}
428424

429-
bool skipThisToken = skipSubSyntaxSeparator && pattern.hasSyntax();
430-
431-
if ( !skipThisToken )
425+
if ( !( skipSubSyntaxSeparator && pattern.hasSyntax() ) )
432426
pushToken( tokens, currentType, segmentText );
433427

434428
currentBytePos = segmentEndBytePos;
435429
}
436430

437-
patternTextStr =
438-
textv.substr( fullMatchStart, fullMatchEnd - fullMatchStart );
439-
440431
if ( pattern.hasSyntax() ) {
441432
pushSubsyntax( curState, retState, pattern, patternIndex + 1,
442-
patternTextStr );
433+
( patternTextStr =
434+
textv.substr( fullMatchStart,
435+
fullMatchEnd - fullMatchStart ) ) );
443436
} else if ( pattern.patterns.size() > 1 ) {
444437
setSubsyntaxPatternIdx( curState, retState, patternIndex + 1 );
445438
}

src/eepp/ui/uicodeeditor.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5203,9 +5203,14 @@ void UICodeEditor::findRegionsDelayed() {
52035203
UISceneNode* sceneNode = getUISceneNode();
52045204
if ( sceneNode ) {
52055205
TextDocument* doc = mDoc.get();
5206-
sceneNode->debounce( [doc]() { doc->getFoldRangeService().findRegions(); },
5207-
mFoldsIsFirst ? Milliseconds( 100 ) : mFoldsRefreshTime,
5208-
mTagFoldRange );
5206+
sceneNode->debounce(
5207+
[this, doc]() {
5208+
if ( doc->getHighlighter()->isTokenizingAsync() )
5209+
findRegionsDelayed();
5210+
else
5211+
doc->getFoldRangeService().findRegions();
5212+
},
5213+
mFoldsIsFirst ? Milliseconds( 100 ) : mFoldsRefreshTime, mTagFoldRange );
52095214

52105215
mFoldsIsFirst = false;
52115216
}

0 commit comments

Comments
 (0)