Skip to content

Commit ba8d33b

Browse files
committed
#3496 languagetool: fix crash when closing QOwnNotes while LanguageTool was active
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent 6159115 commit ba8d33b

6 files changed

Lines changed: 21 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
scans while typing when the backlink inputs did not change, and by computing
99
backlink-relative note paths without touching every note file on disk
1010
(for [#3587](https://github.com/pbek/QOwnNotes/issues/3587))
11+
- Fixed a crash when closing QOwnNotes while **LanguageTool** was active by
12+
clearing checker state without triggering editor rehighlighting during text
13+
edit destruction (for [#3496](https://github.com/pbek/QOwnNotes/issues/3496))
1114

1215
## 26.6.3
1316

src/services/harperchecker.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ void HarperChecker::setTextEdit(QPlainTextEdit *textEdit) {
6868
scheduleCheck(true);
6969
}
7070

71-
void HarperChecker::clearForTextEdit(QPlainTextEdit *textEdit) {
71+
void HarperChecker::clearForTextEdit(QPlainTextEdit *textEdit, bool updateBlocks) {
7272
if (_textEdit == textEdit) {
73-
clearCurrentState();
73+
clearCurrentState(updateBlocks);
7474
_textEdit.clear();
7575
_document.clear();
7676
}
7777
}
7878

79-
void HarperChecker::clearCurrentState() {
79+
void HarperChecker::clearCurrentState(bool updateBlocks) {
8080
_debounceTimer->stop();
8181
_client->cancelAllRequests();
8282
_pendingRequests.clear();
@@ -88,7 +88,9 @@ void HarperChecker::clearCurrentState() {
8888
if (oldAvailable != _available) {
8989
Q_EMIT availabilityChanged(_available);
9090
}
91-
Q_EMIT blockMatchesUpdated(QVector<int>());
91+
if (updateBlocks) {
92+
Q_EMIT blockMatchesUpdated(QVector<int>());
93+
}
9294
}
9395

9496
void HarperChecker::invalidateBlock(int blockNumber) { _cache.remove(blockNumber); }

src/services/harperchecker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class HarperChecker : public QObject {
3131
static HarperChecker *instance();
3232

3333
void setTextEdit(QPlainTextEdit *textEdit);
34-
void clearForTextEdit(QPlainTextEdit *textEdit);
35-
void clearCurrentState();
34+
void clearForTextEdit(QPlainTextEdit *textEdit, bool updateBlocks = true);
35+
void clearCurrentState(bool updateBlocks = true);
3636
void invalidateBlock(int blockNumber);
3737
void scheduleCheck(bool immediate = false);
3838
void recheckNow();

src/services/languagetoolchecker.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,24 @@ void LanguageToolChecker::setTextEdit(QPlainTextEdit *textEdit) {
7070
scheduleCheck(true);
7171
}
7272

73-
void LanguageToolChecker::clearForTextEdit(QPlainTextEdit *textEdit) {
73+
void LanguageToolChecker::clearForTextEdit(QPlainTextEdit *textEdit, bool updateBlocks) {
7474
if (_textEdit == textEdit) {
75-
clearCurrentState();
75+
clearCurrentState(updateBlocks);
7676
_textEdit.clear();
7777
_document.clear();
7878
}
7979
}
8080

81-
void LanguageToolChecker::clearCurrentState() {
81+
void LanguageToolChecker::clearCurrentState(bool updateBlocks) {
8282
_debounceTimer->stop();
8383
_client->cancelAllRequests();
8484
_pendingRequests.clear();
8585
_pendingRequestId = 0;
8686
_cache.clear();
8787
_warningShown = false;
88-
Q_EMIT blockMatchesUpdated(QVector<int>());
88+
if (updateBlocks) {
89+
Q_EMIT blockMatchesUpdated(QVector<int>());
90+
}
8991
}
9092

9193
void LanguageToolChecker::invalidateBlock(int blockNumber) { _cache.remove(blockNumber); }

src/services/languagetoolchecker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class LanguageToolChecker : public QObject {
3030
static LanguageToolChecker *instance();
3131

3232
void setTextEdit(QPlainTextEdit *textEdit);
33-
void clearForTextEdit(QPlainTextEdit *textEdit);
34-
void clearCurrentState();
33+
void clearForTextEdit(QPlainTextEdit *textEdit, bool updateBlocks = true);
34+
void clearCurrentState(bool updateBlocks = true);
3535
void invalidateBlock(int blockNumber);
3636
void scheduleCheck(bool immediate = false);
3737
void recheckNow();

src/widgets/qownnotesmarkdowntextedit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3619,10 +3619,10 @@ QOwnNotesMarkdownTextEdit::~QOwnNotesMarkdownTextEdit() {
36193619
qDebug() << "*** QOwnNotesMarkdownTextEdit DESTROYED ***" << this << objectName();
36203620
closeMarkdownLspDocument();
36213621
#ifdef LANGUAGETOOL_ENABLED
3622-
LanguageToolChecker::instance()->clearForTextEdit(this);
3622+
LanguageToolChecker::instance()->clearForTextEdit(this, false);
36233623
#endif
36243624
#ifdef HARPER_ENABLED
3625-
HarperChecker::instance()->clearForTextEdit(this);
3625+
HarperChecker::instance()->clearForTextEdit(this, false);
36263626
#endif
36273627
// Unregister if this was the active editor
36283628
unregisterAsActiveEditor();

0 commit comments

Comments
 (0)