Skip to content

Commit 0040fcd

Browse files
committed
improve command detection in multi-line arguments
fix #4030
1 parent 6ff4fdc commit 0040fcd

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/latexparser/latexparsing.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,29 @@ Token getCommandTokenFromToken(TokenList tl, Token tk)
16061606
if (elem.level < level)
16071607
break;
16081608
}
1609+
// handle special case that open is not in the same line as the command token (e.g. issue #4030)
1610+
if(result.dlh==nullptr){
1611+
// search for command in previous lines
1612+
QDocumentLineHandle *dlh=tl.first().dlh;
1613+
if(dlh){
1614+
QDocument *doc = dlh->document();
1615+
int lineNr = doc->indexOf(dlh);
1616+
while(lineNr>0){
1617+
QDocumentLineHandle *previous = doc->line(lineNr - 1).handle();
1618+
TokenList tl= previous->getCookieLocked(QDocumentLine::LEXER_COOKIE).value<TokenList>();
1619+
for(int i=tl.length()-1;i>=0;--i){
1620+
Token elem = tl.at(i);
1621+
if (elem.level == level && (elem.type == Token::command || elem.type == Token::commandUnknown) ) {
1622+
result = elem;
1623+
return result;
1624+
}
1625+
if (elem.level < level)
1626+
break;
1627+
}
1628+
--lineNr;
1629+
}
1630+
}
1631+
}
16091632
return result;
16101633
}
16111634

src/tests/latexparsing_t.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,9 @@ void LatexParsingTest::test_getCommandFromToken_data() {
10021002
QTest::newRow("multi-line") << "bummerang \\section{abc\n cde}"
10031003
<< 0 << 1
10041004
<< "\\section";
1005+
QTest::newRow("multi-line, brace in new line") << "bummerang \\section\n{abc cde}"
1006+
<< 0 << 1
1007+
<< "\\section";
10051008

10061009

10071010
}

0 commit comments

Comments
 (0)