From ae1d09cab88f12247d4223c15311d1087c299161 Mon Sep 17 00:00:00 2001 From: Alan Kilborn Date: Sun, 11 Aug 2024 08:12:19 -0400 Subject: [PATCH] Improve Python smart indent in case of string Improve Python smart indent by using style context. Fix #15534, close #15535 --- PowerEditor/src/Notepad_plus.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 8ae42ef19..98885af57 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -3771,7 +3771,10 @@ void Notepad_plus::maintainIndentation(wchar_t ch) // colon optionally followed by only whitespace and/or start-of-comment, but NOT on a line that is already a comment const char colonExpr[] = "^[^#]*\\K:[ \t]*(#|$)"; - if (_pEditView->execute(SCI_SEARCHINTARGET, strlen(colonExpr), reinterpret_cast(colonExpr)) >= 0) + auto posColon = _pEditView->execute(SCI_SEARCHINTARGET, strlen(colonExpr), reinterpret_cast(colonExpr)); + + // when colon found, additionally check that it is not in a comment, inside a string, etc. + if ((posColon >= 0) && (_pEditView->execute(SCI_GETSTYLEINDEXAT, posColon) == SCE_P_OPERATOR)) { _pEditView->setLineIndent(curLine, indentAmountPrevLine + tabWidth); }