mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Fix Lexer::getLongString prefix pruning logic
This fixes 3 bugs:
1/ only spaces are considered as part of the prefix
2/ leading tabs are removed unconditionally
3/ off-by-one error in the removal
The new intended behavior is:
1/ find the prefix (sequence of spaces and tabs) before the first
line; remove this prefix from the line
2/ on the next lines, check whether they start with the same prefix,
and if they do, strip this prefix
(cherry picked from commit 48f099d93a
)
This commit is contained in:
parent
3bb2937562
commit
cc28353922
@ -738,7 +738,7 @@ docstring Lexer::getLongString(docstring const & endtoken)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
if (firstline) {
|
if (firstline) {
|
||||||
size_t i = tmpstr.find_first_not_of(char_type(' '));
|
size_t i = tmpstr.find_first_not_of(from_ascii(" \t"));
|
||||||
if (i != string::npos)
|
if (i != string::npos)
|
||||||
prefix = tmpstr.substr(0, i);
|
prefix = tmpstr.substr(0, i);
|
||||||
firstline = false;
|
firstline = false;
|
||||||
@ -747,10 +747,10 @@ docstring Lexer::getLongString(docstring const & endtoken)
|
|||||||
|
|
||||||
// further lines in long strings may have the same
|
// further lines in long strings may have the same
|
||||||
// whitespace prefix as the first line. Remove it.
|
// whitespace prefix as the first line. Remove it.
|
||||||
if (prefix.length() && prefixIs(tmpstr, prefix))
|
if (!prefix.empty() && prefixIs(tmpstr, prefix))
|
||||||
tmpstr.erase(0, prefix.length() - 1);
|
tmpstr.erase(0, prefix.length());
|
||||||
|
|
||||||
str += ltrim(tmpstr, "\t") + '\n';
|
str += tmpstr + '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pimpl_->is)
|
if (!pimpl_->is)
|
||||||
|
Loading…
Reference in New Issue
Block a user