Skip to content

Commit

Permalink
Fix spell check refresh (for small documents) (#1416)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo authored Apr 13, 2023
2 parents 8c9f84d + 0ffb6ee commit 239bc88
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions novelwriter/gui/doceditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,14 +724,13 @@ def setDictionaries(self):
_, theProvider = self.spEnchant.describeDict()

self.spellDictionaryChanged.emit(str(theLang), str(theProvider))

if not self._bigDoc:
self.spellCheckDocument()

return True

def toggleSpellCheck(self, theMode):
"""This is the master spell check setting function, and this one
"""This is the main spell check setting function, and this one
should call all other setSpellCheck functions in other classes.
If the spell check mode (theMode) is not defined (None), then
toggle the current status saved in this class.
Expand All @@ -754,7 +753,8 @@ def toggleSpellCheck(self, theMode):
self.mainGui.mainMenu.setSpellCheck(theMode)
self.theProject.data.setSpellCheck(theMode)
self.highLight.setSpellCheck(theMode)
if not self._bigDoc:
if not self._bigDoc or theMode is False:
# We don't run the spell checker automatically on big docs
self.spellCheckDocument()

logger.debug("Spell check is set to '%s'", str(theMode))
Expand All @@ -768,18 +768,16 @@ def spellCheckDocument(self):
the undo stack, so we only do it for big documents.
"""
logger.debug("Running spell checker")
if self._spellCheck:
bfTime = time()
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
if self._bigDoc:
theText = self.getText()
self.setPlainText(theText)
else:
self.highLight.rehighlight()
qApp.restoreOverrideCursor()
afTime = time()
logger.debug("Document highlighted in %.3f ms", 1000*(afTime-bfTime))
self.mainGui.mainStatus.setStatus(self.tr("Spell check complete"))
start = time()
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
if self._bigDoc:
# This is much faster for large documents
self.setPlainText(self.getText())
else:
self.highLight.rehighlight()
qApp.restoreOverrideCursor()
logger.debug("Document highlighted in %.3f ms", 1000*(time() - start))
self.mainGui.mainStatus.setStatus(self.tr("Spell check complete"))

return True

Expand Down

0 comments on commit 239bc88

Please sign in to comment.