https://bugs.kde.org/show_bug.cgi?id=450951
Bug ID: 450951 Summary: Syntax highlighting mode not persisting across file (auto)reload when set in status bar menu Product: kate Version: Git Platform: Compiled Sources OS: Linux Status: REPORTED Severity: normal Priority: NOR Component: general Assignee: kwrite-bugs-n...@kde.org Reporter: david.av.schlos...@gmail.com Target Milestone: --- SUMMARY After manually selecting the file mode from the status bar menu, thus implicitly selecting the syntax highlighting mode, the syntax highlighting mode does not get persisted across file reloading or auto-reloading, despite the file mode and the status bar menu button text remaining unchanged. If the document's file type can't be determined automatically, i.e. it has no known file extension nor a recognizable mime-type, the highlighting disappears altogether (set to None), even though the user probably feels like they made their preference pretty explicit. STEPS TO REPRODUCE 1. Open kate/kwrite and fill a new file with something unrecognizable to mime-magic (or /usr/bin/file), but still valid for syntax highlighting. INI for example: ``` [Some Group] SomeEntry=Some Value ``` 2. Save the file without a file extension (e.g. /tmp/testrc) 3. Select the mode corresponding to the syntax from the status bar menu. (Configuration/INI Files, in this case) 4. Reload the file (F5) OBSERVED RESULT The syntax highlighting disappears (reverts to None, more precisely), despite the status bar menu still displaying the correct mode. EXPECTED RESULT The selected syntax highlighting mode persists after the file is reloaded. SOFTWARE/OS Operating System: Kubuntu 21.10 KDE Plasma Version: 5.24.2 KDE Frameworks Version: 5.91.0 Qt Version: 5.15.2 Kernel Version: 5.13.0-32-generic (64-bit) Graphics Platform: X11 ADDITIONAL INFORMATION This issue arose while watching changes to *rc configs live using autoreload, and their file type (INI) is often not detected automatically. While this issue can be fixed by manually selecting the highlighting mode from Tools/Highlighting in the menu bar, that's not probably not immediately obvious to most users, at least it wasn't to me, and probably leads people to tediously select the same, seemingly already selected mode from the status bar menu after the reload, as I first did. My suggestion is simply to mark the highlighting mode, in addition to the file mode, as having been user selected (`m_hlSetByUser = true;`), when chosen from the status bar menu. Otherwise, the menu's tooltip ("Syntax highlighting") is rather misleading, even to those who understand the distinction between file mode and highlighting mode, because it actually selects the file mode and only sets the highlighting mode indirectly. Here's a very simple fix I propose: In ktexteditor/src/mode/katemodemenulist.cpp:506 ``` // Apply syntax highlighting KTextEditor::DocumentPrivate *doc = m_doc; if (doc && item->hasMode()) { +++ // Mark highlighting mode as being user-selected +++ doc->setDontChangeHlOnSave(); doc->updateFileType(item->getMode()->name, true); } ``` As an aside, the function `setDontChangeHlOnSave` could probably use a more general name, or just be made into generic setter. It just marks the highlighting as being user-selected and can be applied outside of just saving, like reloading in this case. -- You are receiving this mail because: You are watching all bug changes.