Improve Python smart indent in case of string

Improve Python smart indent by using style context.

Fix #15534, close #15535
This commit is contained in:
Alan Kilborn 2024-08-11 08:12:19 -04:00 committed by Don Ho
parent 48a2b30c13
commit ae1d09cab8
1 changed files with 4 additions and 1 deletions

View File

@ -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<LPARAM>(colonExpr)) >= 0)
auto posColon = _pEditView->execute(SCI_SEARCHINTARGET, strlen(colonExpr), reinterpret_cast<LPARAM>(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);
}