diff --git a/autotests/folding/test.c.fold b/autotests/folding/test.c.fold --- a/autotests/folding/test.c.fold +++ b/autotests/folding/test.c.fold @@ -54,3 +54,15 @@ */ #endif + +/* + * Empty lines after a line continuation character (see bug #405903) + */ +#define one \ +two \ + +int i = 0; // this should not be highlighted as a macro +char* str = "string \ + + +int i = 0; // this should not be highlighted as a string diff --git a/autotests/html/test.c.html b/autotests/html/test.c.html --- a/autotests/html/test.c.html +++ b/autotests/html/test.c.html @@ -60,4 +60,16 @@ */ #endif + +/* + * Empty lines after a line continuation character (see bug #405903) + */ +#define one \ +two \ + +int i = 0; // this should not be highlighted as a macro +char* str = "string \ + + +int i = 0; // this should not be highlighted as a string diff --git a/autotests/input/test.c b/autotests/input/test.c --- a/autotests/input/test.c +++ b/autotests/input/test.c @@ -54,3 +54,15 @@ */ #endif + +/* + * Empty lines after a line continuation character (see bug #405903) + */ +#define one \ +two \ + +int i = 0; // this should not be highlighted as a macro +char* str = "string \ + + +int i = 0; // this should not be highlighted as a string diff --git a/autotests/reference/test.c.ref b/autotests/reference/test.c.ref --- a/autotests/reference/test.c.ref +++ b/autotests/reference/test.c.ref @@ -54,3 +54,15 @@ */

#endif
+
+/*
+ * Empty lines after a line continuation character (see bug #405903)
+ */
+#define one \
+two \
+
+int i = 0; // this should not be highlighted as a macro
+char* str = "string \
+
+
+int i = 0; // this should not be highlighted as a string
diff --git a/src/lib/abstracthighlighter.cpp b/src/lib/abstracthighlighter.cpp --- a/src/lib/abstracthighlighter.cpp +++ b/src/lib/abstracthighlighter.cpp @@ -145,8 +145,23 @@ * see https://phabricator.kde.org/D18509 */ int endlessLoopingCounter = 0; - while (!stateData->topContext()->lineEmptyContext().isStay()) { - if (!d->switchContext(stateData, stateData->topContext()->lineEmptyContext(), QStringList())) + while (!stateData->topContext()->lineEmptyContext().isStay() || (stateData->topContext()->lineEmptyContext().isStay() && !stateData->topContext()->lineEndContext().isStay())) { + /** + * line empty context switches + */ + if (!stateData->topContext()->lineEmptyContext().isStay()) { + if (!d->switchContext(stateData, stateData->topContext()->lineEmptyContext(), QStringList())) { + /** + * end when trying to #pop the main context + */ + break; + } + /** + * line end context switches only when lineEmptyContext is #stay. This avoids + * skipping empty lines after a line continuation character (see bug 405903) + */ + } else if (!stateData->topContext()->lineEndContext().isStay() && + !d->switchContext(stateData, stateData->topContext()->lineEndContext(), QStringList())) break; // guard against endless loops