Disable initial spell checking for large documents

This commit is contained in:
Veronica K. B. Olsen
2019-11-19 18:48:44 +01:00
parent 2217f1d89c
commit 3c6350a4da
2 changed files with 32 additions and 6 deletions
+1
View File
@@ -93,6 +93,7 @@ class Config:
self.wordCountTimer = 5.0 self.wordCountTimer = 5.0
self.showTabsNSpaces = False self.showTabsNSpaces = False
self.showLineEndings = False self.showLineEndings = False
self.bigDocLimit = 800
self.fmtApostrophe = nwUnicode.U_RSQUO self.fmtApostrophe = nwUnicode.U_RSQUO
self.fmtSingleQuotes = [nwUnicode.U_LSQUO,nwUnicode.U_RSQUO] self.fmtSingleQuotes = [nwUnicode.U_LSQUO,nwUnicode.U_RSQUO]
+31 -6
View File
@@ -53,6 +53,7 @@ class GuiDocEditor(QTextEdit):
self.wordCount = 0 self.wordCount = 0
self.paraCount = 0 self.paraCount = 0
self.lastEdit = 0 self.lastEdit = 0
self.bigDoc = False
self.nonWord = "\"'" self.nonWord = "\"'"
# Typography # Typography
@@ -114,17 +115,22 @@ class GuiDocEditor(QTextEdit):
return return
def clearEditor(self): def clearEditor(self):
"""Clear the current document and reset all document related
flags and counters.
"""
self.nwDocument.clearDocument() self.nwDocument.clearDocument()
self.setReadOnly(True) self.setReadOnly(True)
self.clear() self.clear()
self.wcTimer.stop() self.wcTimer.stop()
self.theHandle = None self.theHandle = None
self.charCount = 0 self.charCount = 0
self.wordCount = 0 self.wordCount = 0
self.paraCount = 0 self.paraCount = 0
self.lastEdit = 0 self.lastEdit = 0
self.bigDoc = False
self.hasSelection = False self.hasSelection = False
self.setDocumentChanged(False) self.setDocumentChanged(False)
@@ -214,8 +220,12 @@ class GuiDocEditor(QTextEdit):
return False return False
self.hLight.setHandle(tHandle) self.hLight.setHandle(tHandle)
# Check that the document is not too big for full, initial spell
# checking. If it is too big, we switch to only check as we type
self._checkDocSize(len(theDoc))
spTemp = self.hLight.spellCheck spTemp = self.hLight.spellCheck
self.hLight.spellCheck = False self.hLight.spellCheck = not self.bigDoc
bfTime = time() bfTime = time()
self.setPlainText(theDoc) self.setPlainText(theDoc)
@@ -696,9 +706,24 @@ class GuiDocEditor(QTextEdit):
self.theParent.statusBar.setCounts(self.charCount,self.wordCount,self.paraCount) self.theParent.statusBar.setCounts(self.charCount,self.wordCount,self.paraCount)
self.theParent.treeView.propagateCount(tHandle, self.wordCount) self.theParent.treeView.propagateCount(tHandle, self.wordCount)
self.theParent.treeView.projectWordCount() self.theParent.treeView.projectWordCount()
self._checkDocSize(self.charCount)
return return
def _checkDocSize(self, theSize):
"""Check if document size crosses the big document limit set in
config. If so, we will set the big document flag to True.
"""
if theSize > self.mainConf.bigDocLimit*1000:
logger.info(
"The document size is %d > %d, big doc mode is enabled" % (
theSize, self.mainConf.bigDocLimit*1000
))
self.bigDoc = True
else:
self.bigDoc = False
return
def _wrapSelection(self, tBefore, tAfter): def _wrapSelection(self, tBefore, tAfter):
"""Wraps the selected text in whatever is in tBefore and tAfter. """Wraps the selected text in whatever is in tBefore and tAfter.
If there is no selection, the autoSelect setting decides the If there is no selection, the autoSelect setting decides the