function handleScintillaENTER( byval uMsg as MSG ) as boolean
' Catch any ENTER key destined for the Scintilla editor and beautify the
' current text line. We replace the line with our new code and then allow
' the ENTER key to continue to pass on to Scintilla where it will do the
' insertion of the ENTER character. Scintilla will then fire SCN_CHARADDED
' where we do additional things like AutoIndent.
dim pDoc as clsDocument ptr = gApp.GetDocumentPtrByWindow( uMsg.HWnd )
if pDoc = 0 then return false
dim as HWND hEdit = pDoc->hWndActiveScintilla
if (uMsg.HWnd = hEdit) andalso (uMsg.message = WM_KEYDOWN) andalso (uMsg.wParam = VK_RETURN) then
dim as long nCurLine = pDoc->GetCurrentLineNumber()
dim as string strLine = pDoc->GetLine(nCurLine)
' CALL YOUR FORMATTING ROUTINE HERE AND RETURN THE NEW LINE
' Beautify the current line
'dim as string strNewLine ='AddSpacesAroundOperators( strLine )
' Replace the old line with our new line (don't use pDoc->SetLine)
dim as long lineStart = SendMessage( hEdit, SCI_POSITIONFROMLINE, nCurLine, 0)
dim as long lineEnd = SendMessage( hEdit, SCI_GETLINEENDPOSITION, nCurLine, 0)
SendMessage( hEdit, SCI_SETSELECTIONSTART, lineStart, 0)
SendMessage( hEdit, SCI_SETSELECTIONEND, lineEnd, 0)
SendMessage( hEdit, SCI_REPLACESEL, 0, cast(LPARAM, strptr(strNewLine)) )
end if
' we want our message to continue so return FALSE
return false
end function
' ========================================================================================
' Sets the interval frequency for tick marks in a trackbar.
' ========================================================================================
PRIVATE SUB Trackbar_SetTicFreq (BYVAL hTrackbar AS HWND, BYVAL wFreq AS WORD)
SendMessageW(hTrackbar, TBM_SETTICFREQ, cast(WPARAM, wFreq), 0)
END SUB
' ========================================================================================
' // Adds a Trackbar control
DIM hTrackBar AS HWND = pWindow.AddControl("Trackbar", hWin, IDC_TRACKBAR, "", 75, 60, 240, 32)
' // Set the range values
Trackbar_SetRangeMin hTrackBar, 0, TRUE
Trackbar_SetRangeMax hTrackBar, 20, TRUE
' new
' Trackbar_SetTicfreq hTrackBar, 2, 0 ' doesnt exist in cWindow ?
' SendMessageW hTrackBar, TBM_SETTICFREQ, 2,0 ' included in cWindow or commctrl ?
if a>b then
print "hello"
else
print "china"
end if
do while a>b
print "word"
loop
end ifI consulted an DeepSeek(AI) tool for analysis, and it pointed out the root cause: my formatting function calls SetLine to rewrite the entire line, which triggers the SCN_MODIFIED notification and forces bNeedsParsing = true. This marks the global document's nested level and keyword parsing cache as outdated, so the reference data used to calculate multi-layer indentation stays invalid all the time.