Skip to content

Link format fix

Igor Poboiko requested to merge poboiko/kpimtextedit:link-format-fix into master

The default QTextEdit behavior is following:

  • the current char format corresponds to the symbol right before the cursor position.
  • if the cursor is at the start of the block, the format is grabbed from the symbol after the cursor.

It works well with standard formatting (bold, underline, etc), which can easily be enabled / disabled using corresponding QActions. Note that the behavior is also the same for, say, LibreOffice.

However, it does not work well with hyperlinks. If the document ends with a link, it is virtually impossible to start typing normal text right after this link (i.e. to reset the char format). The only way to do it is to use copy-paste (i.e. paste some normal text, preserving formatting), which is quite frustrating.

For the same reason it's not easy to write some text right after hyperlink. I believe it's the reason behind this tiny whitespace in insertHtml inside richTextComposer.

The workaround is following: alter the default behiour and take the character format from symbol right after the link if the cursor points at the end of the link (this is also the way LibreOffice behaves).

Screencast showing the issue

Before

link_before

After

link_after

Merge request reports