Bug 383350 - KSyntaxHighlighting::SyntaxHighlighter removes QTextBlock::userData() silently
Summary: KSyntaxHighlighting::SyntaxHighlighter removes QTextBlock::userData() silently
Status: RESOLVED WORKSFORME
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: framework (show other bugs)
Version: unspecified
Platform: Microsoft Windows Microsoft Windows
: NOR major
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-10 10:23 UTC by Szyk Cech
Modified: 2017-09-04 19:11 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Szyk Cech 2017-08-10 10:23:44 UTC
Hi!
KSyntaxHighlighting::SyntaxHighlighter removes QTextBlock::userData() silently.
I have bookmarks in my editor and they are based on QTextBlock::setUserData(). I can navigate in code and edit it without problems and without bookmark disappearance. But when I am in line where is bookmark and I edit this line then bookmark disappear. It seems that some other object appear in its place. But I can't figure out its class.
This strange behaviour occurs when I switch syntax highlighting from my custom engine to KSyntaxHighlighting::SyntaxHighlighter. My old syntax highlighter does not remove bookmarks.

thanks and best regards
Szyk Cech
Comment 1 Dominik Haumann 2017-08-10 14:56:51 UTC
Indeed, this is because the Syntax-highlighting framework uses the userData itself to store the State and folding infos, see:
https://github.com/KDE/syntax-highlighting/blob/master/src/lib/syntaxhighlighter.cpp
Comment 2 Szyk Cech 2017-08-10 17:35:48 UTC
So: how is the recommended way to implement bookmarks? Should I dig in Kate code? Maybe someone can explain it in few words. This will save me hours...
Comment 3 Dominik Haumann 2017-09-04 18:13:36 UTC
There is one possible solution: Instead of using the ready-made QSyntaxHighlighter based solution, you could implement your own QSyntaxHighlighter-based solution.

This is e.g. done in this commit in the KDE PIM suite:
https://phabricator.kde.org/D7672
https://cgit.kde.org/kpimtextedit.git/commit/?id=c775ce3a438814f82cb1ba9c2c8671b9f5be08c4

Here, the class PlainTextSyntaxSpellCheckingHighlighter derives from Sonnet::Highlighter AND KSyntaxHighlighting::AbstractHighlighter.

If you follow this same route, you will be able to do what you want.

@Volker: I think this is the only solution to this problem, right? If so, I think we can close this bug report, correct?
Comment 4 Dominik Haumann 2017-09-04 19:11:57 UTC
Hi Szyk, after talking to Volker about this, the solution you can find in the linked sources is the only way to go if you need your own custom QTextBlocks. But give this works, there is no real bug, so we will close this as works-for-me.

Kate will later use this approach as well.