mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
bug-fix: fix leading spaces issue of VCodeBlockHighlightHelper
For example, a token " abc" in text "def\n abc", the leading space may be consumed by the former "\n".
This commit is contained in:
parent
2c527201b8
commit
05e4159530
@ -111,8 +111,20 @@ static void matchTokenRelaxed(const QString &p_text, const QString &p_tokenStr,
|
|||||||
int &p_index, int &p_start, int &p_end)
|
int &p_index, int &p_start, int &p_end)
|
||||||
{
|
{
|
||||||
QString regStr = QRegExp::escape(p_tokenStr);
|
QString regStr = QRegExp::escape(p_tokenStr);
|
||||||
|
|
||||||
|
// Remove the leading spaces.
|
||||||
|
int nonSpaceIdx = 0;
|
||||||
|
while (nonSpaceIdx < regStr.size() && regStr[nonSpaceIdx].isSpace()) {
|
||||||
|
++nonSpaceIdx;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nonSpaceIdx > 0 && nonSpaceIdx < regStr.size()) {
|
||||||
|
regStr.remove(0, nonSpaceIdx);
|
||||||
|
}
|
||||||
|
|
||||||
// Do not replace the ending '\n'.
|
// Do not replace the ending '\n'.
|
||||||
regStr.replace(QRegExp("\n(?!$)"), "\\s+");
|
regStr.replace(QRegExp("\n(?!$)"), "\\s+");
|
||||||
|
|
||||||
QRegExp regExp(regStr);
|
QRegExp regExp(regStr);
|
||||||
p_start = p_text.indexOf(regExp, p_index);
|
p_start = p_text.indexOf(regExp, p_index);
|
||||||
if (p_start == -1) {
|
if (p_start == -1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user