Help with formatting module & some feature suggestions

Started by fbfans, July 04, 2026, 01:45:03 AM

Previous topic - Next topic

Paul Squires

@hajubu

I have fixed the TODO parsing. Use the files "modParser.inc", and "modParser.bi" in the development branch:  https://github.com/PaulSquires/tiko/tree/development/src

I tested the new code with the following test variations:
'TODO: This is sample text for "I need to do" in the last line 6
'ToDo: (upper and lowercase)
'    todo: (leading spaces)

/'
'     ToDo: (in multiline comment, upper/lower, leading spaces)
'/
Paul Squires
PlanetSquires Software

hajubu


fbfans

Hello Paul,

I've been testing my formatting module again, and unfortunately it still breaks the auto-indentation. I've attached my code — could you please take a look at it when you have a moment? Thank you.

I noticed that you're already preparing the next release and I saw your planned work. I think there's still some room to improve the overall user experience of Tiko, and while you may already be working on some of these, I feel the following issues are quite important:

1.Sidebar refresh problem: When opening or closing files, the sidebar doesn't update synchronously, and there's no manual refresh button either.
2.Function list collapse/expand is not working (I mentioned this in my first post). The Explorer and Bookmarks panels work fine, but the Function list doesn't collapse/expand properly. This makes it less intuitive when many files are open.

3.Bookmarks show garbled text for Chinese characters, and only work correctly when the file encoding is ANSI. You previously fixed the garbled text issue in the TODO list — could you perhaps apply a similar elegant fix here?
4.Suggestion for hover hints on #include lines: For example, on #include once "AfxNova/Dwstring.inc", it would be helpful to show a tooltip like "Dwstring.inc, right-click to open". It took me a long time to discover that Tiko even supports this feature.
5.Localization language selection: Since Tiko already supports several languages, could we have a listbox for selecting the language? It would be much more user-friendly to double-click a file directly.

Thank you for your work on this great editor. I don't mean to put any pressure on you — I just hope that, while you're enjoying coding, you might find some time to address issues like #1 and #2, which would significantly improve the user experience.

Wish you happy coding!

Paul Squires

@fbfans

Thanks for the source file and suggestions. I will look at the formatter and your suggestions as soon as I can. I have a short list of things to fix/implement before I can get to your list.

QuoteSidebar refresh problem: When opening or closing files, the sidebar doesn't update synchronously, and there's no manual refresh button either.
Maybe you can explain this one a bit more. Opening/Closing files should automatically reload the Explorer and Functions panes (maybe the bookmarks list is not being cleared and refreshed?).

What I do need to work on is updating the Functions list in real time as the user types in a Sub/Function  End Sub/End Function combination WITHOUT SAVING. Currently, it is the act of saving the file that triggers a re-parsing of the code thereby updating the Functions list. I plan to switch this to either use continuously scanning background threads, or simply do a re-parse of the code when the ENTER key is pressed.


Paul Squires
PlanetSquires Software

Paul Squires

Quote from: fbfans on July 10, 2026, 05:34:30 AMFunction list collapse/expand is not working (I mentioned this in my first post). The Explorer and Bookmarks panels work fine, but the Function list doesn't collapse/expand properly. This makes it less intuitive when many files are open.

Should be fixed now in "frmFunctions.inc" on the development branch. Just had to slightly change the WM_LBUTTONUP message:

        case WM_LBUTTONUP
            ' determine if we clicked on a function name or a node header
            dim as RECT rc
            dim as long idx = Listbox_ItemFromPoint( hWin, GET_X_LPARAM(_lParam), GET_Y_LPARAM(_lParam))
            ' The return value contains the index of the nearest item in the LOWORD. The HIWORD is zero
            ' if the specified point is in the client area of the list box, or one if it is outside the
            ' client area.
            if hiword(idx) <> 1 then
                dim as clsDocument ptr pDoc = cast(clsDocument ptr, ListBox_GetItemData( hWin, idx ))
                dim as DWSTRING wszCaption = AfxGetListBoxText( hWin, idx )
                if (left(wszCaption, 4) = "true") orelse (left(wszCaption, 5) = "false") then
                    ' Toggle the show/hide of functions under this node
                    if pDoc then pDoc->bFunctionsExpanded = not pDoc->bFunctionsExpanded
                    ' allow listbox click event to fully process before loading new functions
                    PostMessage( hWin, MSG_USER_LOAD_FUNCTIONSFILES, 0, 0 )
                else
                    ' Attempt to show the function name
                    dim as long nLineNum = getFunctionsLinenumber( wszCaption )
                    dim as DWSTRING wszFunctionName = getFunctionsFunctionName( wszCaption )
                    dim as DWSTRING wszDiskFilename
                    if pDoc then wszDiskFilename = pDoc->DiskFilename
                    OpenSelectedDocument( wszDiskFilename, wszFunctionName, nLineNum )
                end if
            end if
Paul Squires
PlanetSquires Software

Paul Squires

Quote from: fbfans on July 10, 2026, 05:34:30 AMBookmarks show garbled text for Chinese characters, and only work correctly when the file encoding is ANSI. You previously fixed the garbled text issue in the TODO list — could you perhaps apply a similar elegant fix here?
This is now fixed in the development branch. "frmBookmarks.inc"

Also, you were correct that the Bookmarks in side panel list were not getting refreshed/updated when "Save" was invoked. This is now fixed.  "frmMainFile.inc"  added "LoadBookmarksFiles()" to the "OnCommand_FileSave()" function.

QuoteSuggestion for hover hints on #include lines: For example, on #include once "AfxNova/Dwstring.inc", it would be helpful to show a tooltip like "Dwstring.inc, right-click to open". It took me a long time to discover that Tiko even supports this feature.
This is harder to implement than it should be (because I had already tried to implement such a feature before :-) )
The problem is that the Scintilla editing control does not expose or fire any type of MouseHover notification message. The hacks that I have read indicate having to subclass each editing window and hook into Scintilla's own message loops. I'm sure that it can be done but I decided against it because it would introduce a layer of complexity that I fear would be brittle and possibly lead to instability.

QuoteLocalization language selection: Since Tiko already supports several languages, could we have a listbox for selecting the language? It would be much more user-friendly to double-click a file directly.
I posit that it is extremely rare that Tiko users switch between localized languages enough to necessitate changing the current UI. Maybe you do with Simplified Chinese and English? But I expect that is the exception rather than the rule.
Paul Squires
PlanetSquires Software

Paul Squires

Quote from: fbfans on July 10, 2026, 05:34:30 AMI've been testing my formatting module again, and unfortunately it still breaks the auto-indentation. I've attached my code — could you please take a look at it when you have a moment? Thank you.
I just started to look at this code. I have translated all of the Chinese comments to English so that I can better understand the intention of the different parts of the code. Give me some time to learn and understand how this works and then I will see if there are ways that I can simplify it. I may also take a look at other solutions from other languages to see how they tackle this type of problem.
Paul Squires
PlanetSquires Software

Paul Squires

Quote from: fbfans on July 04, 2026, 01:45:03 AMI've always wanted to have auto‑formatting while typing, similar to what QB64 does. So I tried to write a module (modformatter.inc) that formats a line immediately after it's entered – mainly adding spaces around operators and such simple things. (I'm a beginner and my code is quite messy, so I'm a bit embarrassed to share it.) I tested the module and it basically works. Then I included my module in frmonmainnotify.inc and added the following code:
case chr(13) ' ENTER KEY PRESSED
        pDoc->AutoCompleteType = AUTOCOMPLETE_NONE
        AttemptAutoInsert()
    ' ===== 新增:格式化上一行(开始)=====
                      pDoc->AutoCompleteType = AUTOCOMPLETE_NONE
                            AttemptAutoInsert()
                           
                            dim nLine as long = pDoc->GetCurrentLineNumber()
                            if nLine > 0 then
                                  dim strPrevLine as string = pDoc->GetLine(nLine - 1)
                                  dim sTrim as string = trim(strPrevLine)
                                 
                                  ' 跳过空行和单行注释
                                  if sTrim <> "" and left(sTrim, 1) <> "'" then
                                        ' 检测是否在多行注释内
                                        dim hEdit as HWND = pDoc->hWndActiveScintilla
                                        dim lineStart as long = SciExec(hEdit, SCI_POSITIONFROMLINE, nLine - 1, 0)
                                        dim style as long = SciExec(hEdit, SCI_GETSTYLEAT, lineStart, 0)
                                        if style <> SCE_B_MULTILINECOMMENT then
                                            dim fmtPrevLine as string = AddSpacesAroundOperators(strPrevLine)
                                            if strPrevLine <> fmtPrevLine then
                                                  pDoc->SetLine(nLine - 1, fmtPrevLine)
                                            end if
                                        end if
                                  end if
                            end if
                            ' ===== 新增:格式化上一行(结束)=====
After recompiling, the formatting works, but it breaks the auto‑indentation. With only one level of indentation it works fine, but with two levels (nested blocks) it stops auto‑indenting.
...
This has been bothering me for a long time. Could you please tell me what I'm doing wrong? Any help would be greatly appreciated.

I went back and re-read your initial post and question.

The purpose of your code is to beautify and format the line that you have just typed and pressed ENTER. Why not do this formatting BEFORE the AttemptAutoInsert(), rather than your approach of AFTER AttemptAutoInsert()? Maybe try replacing the current line with your newly formatted line and then have AttemptAutoInsert() act on that formatted line? That seems more logical to me and it would probably save you from having to determine previously line and indenting, etc.

Maybe something like this:
dim as long nCurLine = pDoc->GetCurrentLineNumber()
dim as string strLine = pDoc->GetLine(nCurLine)
dim as string strNewLine = AddSpacesAroundOperators( strLine )
pDoc->SetLine( nCurLine, strNewLine )
AttemptAutoInsert()

This may work better than your current approach and you wouldn't have to change your existing code very much? I have no idea if it will work but it may be worth a shot to see if it does.


Paul Squires
PlanetSquires Software