[KPIMTextEdit/FindBar] Respect rich formatting and user settings when replacing…

Authored by poboiko on May 1 2020, 5:59 AM.

Description

[KPIMTextEdit/FindBar] Respect rich formatting and user settings when replacing all

Summary:
Instead of converting document to plain text, just loop over all encounters of the search string in the document and replace those.
Otherwise we will lose all formatting in RichTextEditor.

This way we're also able to respect the search settings (case sensitivity, whole word search).
Also, provide user with a visual indication showing how many replacements were made (the same way Kate/KWrite does it).
The latter two points also apply PlainTextEditFindBar.

(in principle, to avoid code duplication, we can move this to FindBarBase.
We only need to access mView->document(), which depends on the underlying text widget,
so we could add a virtual QTextDocument *document() method to FindBarBase and reimplement it)

Test Plan:
Tested case-sensitive and regular expression Replace All on a rich-text document (having a list is already sufficient),
the formatting is not messed up

Reviewers: mlaurent, dvratil

Reviewed By: mlaurent

Subscribers: dvratil, kde-pim

Tags: KDE PIM

Differential Revision: https://phabricator.kde.org/D29318