2727#include " mainwindow.h"
2828#include " qownspellchecker.h"
2929
30+ constexpr qreal ENCRYPTED_TEXT_FONT_SCALE = 1.5 ;
31+
3032QOwnNotesMarkdownHighlighter::QOwnNotesMarkdownHighlighter (QTextDocument *parent,
3133 HighlightingOptions highlightingOptions)
3234 : MarkdownHighlighter(parent, highlightingOptions) {
@@ -41,6 +43,9 @@ void QOwnNotesMarkdownHighlighter::updateCurrentNote(Note *note) {
4143 if (note != nullptr ) {
4244 _currentNote = note;
4345 }
46+
47+ _hasEncrypted = _currentNote ? _currentNote->hasEncryptedNoteText () : false ;
48+ _highlightEncrypted = false ; // Reset state when note changes
4449}
4550
4651/* *
@@ -57,22 +62,44 @@ void QOwnNotesMarkdownHighlighter::highlightBlock(const QString &text) {
5762 setCurrentBlockState (HighlighterState::NoState);
5863 currentBlock ().setUserState (HighlighterState::NoState);
5964
60- // do the Markdown highlighting before the spellcheck highlighting
61- // if we do it afterward, it overwrites the spellcheck highlighting
62- MarkdownHighlighter::highlightMarkdown (text);
63- if (text.contains (QLatin1String (" note://" )) ||
64- text.contains (QChar (' .' ) + _defaultNoteFileExt)) {
65- highlightBrokenNotesLink (text);
65+ // Only check for encryption markers if the note has encrypted content
66+ if (_hasEncrypted) {
67+ if (Note::isEncryptedTextBegin (text)) {
68+ _highlightEncrypted = true ;
69+ }
6670 }
6771
68- // skip spell checking empty blocks and blocks with just "spaces"
69- // the rest of the highlighting needs to be done e.g. for code blocks with
70- // empty lines
71- if (!text.isEmpty () && QOwnSpellChecker::instance ()->isActive ()) {
72- highlightSpellChecking (text);
72+ if (_highlightEncrypted) {
73+ auto format = _formats[MaskedSyntax];
74+ // Reduce the font size for encrypted text
75+ format.setFontPointSize (format.fontPointSize () / ENCRYPTED_TEXT_FONT_SCALE);
76+ setFormat (0 , text.length (), format);
77+ } else {
78+ // do the Markdown highlighting before the spellcheck highlighting
79+ // if we do it afterward, it overwrites the spellcheck highlighting
80+ highlightMarkdown (text);
7381 }
7482
75- highlightScriptingRules (ScriptingService::instance ()->getHighlightingRules (), text);
83+ if (!_highlightEncrypted) {
84+ if (text.contains (QLatin1String (" note://" )) ||
85+ text.contains (QChar (' .' ) + _defaultNoteFileExt)) {
86+ highlightBrokenNotesLink (text);
87+ }
88+
89+ // skip spell checking empty blocks and blocks with just "spaces"
90+ // the rest of the highlighting needs to be done e.g. for code blocks with
91+ // empty lines
92+ if (!text.isEmpty () && QOwnSpellChecker::instance ()->isActive ()) {
93+ highlightSpellChecking (text);
94+ }
95+
96+ highlightScriptingRules (ScriptingService::instance ()->getHighlightingRules (), text);
97+ }
98+
99+ // Only check for encryption end marker if we're highlighting encrypted text
100+ if (_hasEncrypted && _highlightEncrypted && Note::isEncryptedTextEnd (text)) {
101+ _highlightEncrypted = false ;
102+ }
76103
77104 _highlightingFinished = true ;
78105}
0 commit comments