From 0417c51f5c761b5ca77b4ce1b1c6d26e6ae16d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Tue, 3 Jun 2025 21:00:20 -0300 Subject: [PATCH] Fix tokenizer popStack when removing a sub-syntax. --- src/eepp/ui/doc/syntaxtokenizer.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/eepp/ui/doc/syntaxtokenizer.cpp b/src/eepp/ui/doc/syntaxtokenizer.cpp index 744ab2d9f..c98c6bd8e 100644 --- a/src/eepp/ui/doc/syntaxtokenizer.cpp +++ b/src/eepp/ui/doc/syntaxtokenizer.cpp @@ -236,6 +236,8 @@ static inline void popStack( SyntaxStateRestored& curState, SyntaxState& retStat return; } + auto languageIndex = retState.langStack[curState.currentLevel]; + retState.langStack[curState.currentLevel] = 0; setSubsyntaxPatternIdx( curState, retState, SyntaxStateType{} ); @@ -250,6 +252,15 @@ static inline void popStack( SyntaxStateRestored& curState, SyntaxState& retStat if ( retState.langStack[curState.currentLevel] != 0 && retState.langStack[curState.currentLevel] != syntax.getLanguageIndex() ) { setSubsyntaxPatternIdx( curState, retState, SyntaxStateType{} ); + + // Remove all the removed language stack + while ( retState.langStack[curState.currentLevel] == languageIndex && + retState.langStack[curState.currentLevel] != 0 ) { + if ( curState.currentLevel > 0 ) + curState.currentLevel--; + retState.langStack[curState.currentLevel] = 0; + setSubsyntaxPatternIdx( curState, retState, SyntaxStateType{} ); + } } curState = SyntaxTokenizer::retrieveSyntaxState( syntax, retState );