From e7fb5276afd716f3f31a2df5eff760c9319303dd Mon Sep 17 00:00:00 2001 From: David Schulz Date: Tue, 27 Sep 2022 10:49:49 +0200 Subject: [PATCH] Editor: Fix reaplying display settings After setting the document the display settings that are configured in a widget might differ from the ones configured in the document. So Check those values against the desired values from the editor and update if they differ. Change-Id: I30c5eddbb09803451fe03769d8e6d189293c5e86 Reviewed-by: Jarek Kobus --- src/plugins/texteditor/texteditor.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 3b6fd31d0d1..0bfe7c06d16 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -7411,15 +7411,15 @@ void TextEditorWidget::setDisplaySettings(const DisplaySettings &ds) setParenthesesMatchingEnabled(ds.m_highlightMatchingParentheses); d->m_fileEncodingLabelAction->setVisible(ds.m_displayFileEncoding); - if (d->m_displaySettings.m_visualizeWhitespace != ds.m_visualizeWhitespace) { + const QTextOption::Flags currentOptionFlags = document()->defaultTextOption().flags(); + QTextOption::Flags optionFlags = currentOptionFlags; + optionFlags.setFlag(QTextOption::AddSpaceForLineAndParagraphSeparators); + optionFlags.setFlag(QTextOption::ShowTabsAndSpaces, ds.m_visualizeWhitespace); + if (optionFlags != currentOptionFlags) { if (SyntaxHighlighter *highlighter = textDocument()->syntaxHighlighter()) highlighter->rehighlight(); - QTextOption option = document()->defaultTextOption(); - if (ds.m_visualizeWhitespace) - option.setFlags(option.flags() | QTextOption::ShowTabsAndSpaces); - else - option.setFlags(option.flags() & ~QTextOption::ShowTabsAndSpaces); - option.setFlags(option.flags() | QTextOption::AddSpaceForLineAndParagraphSeparators); + QTextOption option = document()->defaultTextOption(); + option.setFlags(optionFlags); document()->setDefaultTextOption(option); }