[KJotsEdit] Reimplement ancient (yet still relevant) workaround for QTextEdit
ClosedPublic

Authored by poboiko on Apr 22 2020, 5:56 PM.

Details

Summary

If the very first block of the document has some style, the cursor is not aware of it.
However, explicitly telling to move the cursor to the start of the document makes the cursor catch up the style
(it's probably slighly better than moving cursor to the left / to the right).

The best I could find was this stackoveflow, unfortunately:
https://stackoverflow.com/questions/37160039/set-default-character-format-in-qtextdocument

Test Plan
  1. Make a document starting with a, say, bold word
  2. Close && Reopen KJots (so that it doesn't reload already used cursor)
  3. Reopen this document -> the cursor is shown as bold from the very beginning

Diff Detail

Repository
R573 KJots
Branch
workaround (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 25751
Build 25769: arc lint + arc unit
poboiko created this revision.Apr 22 2020, 5:56 PM
Restricted Application added a project: KDE PIM. · View Herald TranscriptApr 22 2020, 5:56 PM
poboiko requested review of this revision.Apr 22 2020, 5:56 PM
dfaure requested changes to this revision.Apr 22 2020, 8:35 PM

You say "The format does not seem to exist before the first character" and yet that's exactly where you're moving the cursor.
The code looks ok to me, but the comment is confusing/wrong.

It's just about setting the format of the cursor from the first char. I agree that it's probably a bug that setDocument doesn't trigger that, but I'm not sure the old bug report reference still makes sense here, it feels like a different issue to me (the comment and old workaround says "there's nothing at pos 0, go to pos 1 to grab the format"). Unrelated to your issue and fix.

This revision now requires changes to proceed.Apr 22 2020, 8:35 PM

You say "The format does not seem to exist before the first character" and yet that's exactly where you're moving the cursor.
The code looks ok to me, but the comment is confusing/wrong.

Fair point. I've just copied the comment from the old code, without much thinking about it.

It's just about setting the format of the cursor from the first char. I agree that it's probably a bug that setDocument doesn't trigger that, but I'm not sure the old bug report reference still makes sense here, it feels like a different issue to me (the comment and old workaround says "there's nothing at pos 0, go to pos 1 to grab the format"). Unrelated to your issue and fix.

I think actually that the comment was about the same issue, but the author actually misinterpreted it. When we're going to pos 1 to grab the format, we are still grabbing it from the very first character and very first block in the document. The moveCursor(Start) does it too.


This is freshly opened document without the patch (note the font size is 10 and bold is not marked, although the first symbol is of size 20 and is bold):


This is what happens if I more cursor to the right (the cursor is not visible, but it's at pos 1, at it grabbed style from the first symbol: it's bold and of size 20. I can now freely move it back to the left, and the style will be preserved. That's the old workaround):

And that's the screenshot with this patch (which doesn't move it to the pos 1, but to the start; the cursor is adjusted from the very beginning):

poboiko updated this revision to Diff 80983.Apr 23 2020, 11:02 AM

Updated comment, hopefully it's less confusing

dfaure accepted this revision.Apr 23 2020, 11:29 PM

I see. Thanks for the explanations!

This revision is now accepted and ready to land.Apr 23 2020, 11:29 PM
This revision was automatically updated to reflect the committed changes.