Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo stack is lost after theme change #51

Open
cengels opened this issue Dec 21, 2020 · 0 comments
Open

Undo stack is lost after theme change #51

cengels opened this issue Dec 21, 2020 · 0 comments
Assignees
Labels
bug Something isn't working text area The issue concerns the text area

Comments

@cengels
Copy link
Owner

cengels commented Dec 21, 2020

This is a limitation of the Qt framework. At the moment it is not possible to temporarily disable the QTextDocument's undo manager, nor is it possible for changes to block formats to not be recorded into the current undo command (unlike char formats, which can use QSyntaxHighlighter or QTextLayout::setFormats() to accomplish this).

As a result, the function FormattableTextArea::updateDocumentDefaults() deliberately clears the undo stack after a theme change so that it is not possible to corrupt the document by undoing the new theme's block formats.

There is no easy way to work around this. The only solution I can see is to disable QTextDocument's undo manager entirely and implement a custom undo manager, but that's an enormous amount of work for comparably little payoff. Hm...

@cengels cengels added bug Something isn't working text area The issue concerns the text area labels Dec 21, 2020
@cengels cengels self-assigned this Dec 21, 2020
cengels added a commit that referenced this issue Dec 21, 2020
There should now be no char formats in the document (apart from char
formats for bold and italics) at any point. Everything is done either by
the document's default font options, the TextFormatter class, or
updatePaintNode() directly.

When pasting, the pasted HTML is now dissected and all non-bold
non-italics formats cleanly removed before it is passed on to the
QTextDocument.

When changing themes, we unfortunately still have to go through the
whole document and set the new block formats on each block one-by-one.
This is unavoidable due to the way QTextDocument is structured and the
fact that there is no way to access its individual block formats
(methods like QTextDocument::allFormats() only return copies).

This also results in some issues with the undo/redo system since you
can't exclude block format changes from the undo/redo system (see #51).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working text area The issue concerns the text area
Projects
None yet
Development

No branches or pull requests

1 participant