Remove the big doc limit feature

This commit is contained in:
Veronica Berglyd Olsen
2023-09-06 17:56:39 +02:00
parent 2b98e0d4d2
commit 8c3e906fc5
7 changed files with 3 additions and 72 deletions
-3
View File
@@ -149,7 +149,6 @@ class Config:
self.autoScrollPos = 30 # Start point for typewriter-like scrolling self.autoScrollPos = 30 # Start point for typewriter-like scrolling
self.wordCountTimer = 5.0 # Interval for word count update in seconds self.wordCountTimer = 5.0 # Interval for word count update in seconds
self.bigDocLimit = 800 # Size threshold for heavy editor features in kilobytes
self.incNotesWCount = True # The status bar word count includes notes self.incNotesWCount = True # The status bar word count includes notes
self.highlightQuotes = True # Highlight text in quotes self.highlightQuotes = True # Highlight text in quotes
@@ -588,7 +587,6 @@ class Config:
self.showLineEndings = conf.rdBool(sec, "showlineendings", self.showLineEndings) self.showLineEndings = conf.rdBool(sec, "showlineendings", self.showLineEndings)
self.showMultiSpaces = conf.rdBool(sec, "showmultispaces", self.showMultiSpaces) self.showMultiSpaces = conf.rdBool(sec, "showmultispaces", self.showMultiSpaces)
self.wordCountTimer = conf.rdFlt(sec, "wordcounttimer", self.wordCountTimer) self.wordCountTimer = conf.rdFlt(sec, "wordcounttimer", self.wordCountTimer)
self.bigDocLimit = conf.rdInt(sec, "bigdoclimit", self.bigDocLimit)
self.incNotesWCount = conf.rdBool(sec, "incnoteswcount", self.incNotesWCount) self.incNotesWCount = conf.rdBool(sec, "incnoteswcount", self.incNotesWCount)
self.showFullPath = conf.rdBool(sec, "showfullpath", self.showFullPath) self.showFullPath = conf.rdBool(sec, "showfullpath", self.showFullPath)
self.highlightQuotes = conf.rdBool(sec, "highlightquotes", self.highlightQuotes) self.highlightQuotes = conf.rdBool(sec, "highlightquotes", self.highlightQuotes)
@@ -712,7 +710,6 @@ class Config:
"showlineendings": str(self.showLineEndings), "showlineendings": str(self.showLineEndings),
"showmultispaces": str(self.showMultiSpaces), "showmultispaces": str(self.showMultiSpaces),
"wordcounttimer": str(self.wordCountTimer), "wordcounttimer": str(self.wordCountTimer),
"bigdoclimit": str(self.bigDocLimit),
"incnoteswcount": str(self.incNotesWCount), "incnoteswcount": str(self.incNotesWCount),
"showfullpath": str(self.showFullPath), "showfullpath": str(self.showFullPath),
"highlightquotes": str(self.highlightQuotes), "highlightquotes": str(self.highlightQuotes),
+1 -16
View File
@@ -675,19 +675,6 @@ class GuiPreferencesEditor(QWidget):
self.tr("Available languages are determined by your system.") self.tr("Available languages are determined by your system.")
) )
# Big Document Size Limit
self.bigDocLimit = QSpinBox(self)
self.bigDocLimit.setMinimum(10)
self.bigDocLimit.setMaximum(10000)
self.bigDocLimit.setSingleStep(10)
self.bigDocLimit.setValue(CONFIG.bigDocLimit)
self.mainForm.addRow(
self.tr("Big document limit"),
self.bigDocLimit,
self.tr("Full spell checking is disabled above this limit."),
unit=self.tr("kB")
)
# Word Count # Word Count
# ========== # ==========
self.mainForm.addGroupLabel(self.tr("Word Count")) self.mainForm.addGroupLabel(self.tr("Word Count"))
@@ -775,11 +762,9 @@ class GuiPreferencesEditor(QWidget):
return return
def saveValues(self): def saveValues(self):
"""Save the values set for this tab. """Save the values set for this tab."""
"""
# Spell Checking # Spell Checking
CONFIG.spellLanguage = self.spellLanguage.currentData() CONFIG.spellLanguage = self.spellLanguage.currentData()
CONFIG.bigDocLimit = self.bigDocLimit.value()
# Word Count # Word Count
CONFIG.wordCountTimer = self.wordCountTimer.value() CONFIG.wordCountTimer = self.wordCountTimer.value()
+2 -42
View File
@@ -106,7 +106,6 @@ class GuiDocEditor(QPlainTextEdit):
self._lastEdit = 0 # Time stamp of last edit self._lastEdit = 0 # Time stamp of last edit
self._lastActive = 0.0 # Time stamp of last activity self._lastActive = 0.0 # Time stamp of last activity
self._lastFind = None # Position of the last found search word self._lastFind = None # Position of the last found search word
self._bigDoc = False # Flag for very large document size
self._doReplace = False # Switch to temporarily disable auto-replace self._doReplace = False # Switch to temporarily disable auto-replace
self._queuePos = None # Used for delayed change of cursor position self._queuePos = None # Used for delayed change of cursor position
@@ -238,7 +237,6 @@ class GuiDocEditor(QPlainTextEdit):
self._lastEdit = 0 self._lastEdit = 0
self._lastActive = 0.0 self._lastActive = 0.0
self._lastFind = None self._lastFind = None
self._bigDoc = False
self._doReplace = False self._doReplace = False
self._queuePos = None self._queuePos = None
@@ -396,13 +394,6 @@ class GuiDocEditor(QPlainTextEdit):
qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
self.highLight.setHandle(tHandle) self.highLight.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(docSize)
spTemp = self.highLight.spellCheck
if self._bigDoc:
self.highLight.setSpellCheck(False)
bfTime = time() bfTime = time()
self._allowAutoReplace(False) self._allowAutoReplace(False)
self.setPlainText(theDoc) self.setPlainText(theDoc)
@@ -422,7 +413,6 @@ class GuiDocEditor(QPlainTextEdit):
self.docHeader.setTitleFromHandle(self._docHandle) self.docHeader.setTitleFromHandle(self._docHandle)
self.docFooter.setHandle(self._docHandle) self.docFooter.setHandle(self._docHandle)
self.updateDocMargins() self.updateDocMargins()
self.highLight.setSpellCheck(spTemp)
if tLine is None and self._nwItem is not None: if tLine is None and self._nwItem is not None:
# For large documents, we queue the repositioning until the # For large documents, we queue the repositioning until the
@@ -714,8 +704,7 @@ class GuiDocEditor(QPlainTextEdit):
self.mainGui.mainMenu.setSpellCheck(state) self.mainGui.mainMenu.setSpellCheck(state)
SHARED.project.data.setSpellCheck(state) SHARED.project.data.setSpellCheck(state)
self.highLight.setSpellCheck(state) self.highLight.setSpellCheck(state)
if not self._bigDoc or state is False: if state is False:
# We don't run the spell checker automatically on big docs
self.spellCheckDocument() self.spellCheckDocument()
logger.debug("Spell check is set to '%s'", str(state)) logger.debug("Spell check is set to '%s'", str(state))
@@ -731,11 +720,7 @@ class GuiDocEditor(QPlainTextEdit):
logger.debug("Running spell checker") logger.debug("Running spell checker")
start = time() start = time()
qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
if self._bigDoc: self.highLight.rehighlight()
# This is much faster for large documents
self.setPlainText(self.getText())
else:
self.highLight.rehighlight()
qApp.restoreOverrideCursor() qApp.restoreOverrideCursor()
logger.debug("Document highlighted in %.3f ms", 1000*(time() - start)) logger.debug("Document highlighted in %.3f ms", 1000*(time() - start))
self.statusMessage.emit(self.tr("Spell check complete")) self.statusMessage.emit(self.tr("Spell check complete"))
@@ -1261,8 +1246,6 @@ class GuiDocEditor(QPlainTextEdit):
# Must not be emitted if docHandle is None! # Must not be emitted if docHandle is None!
self.docCountsChanged.emit(self._docHandle, cCount, wCount, pCount) self.docCountsChanged.emit(self._docHandle, cCount, wCount, pCount)
self._checkDocSize(self.document().characterCount())
self.docFooter.updateCounts() self.docFooter.updateCounts()
return return
@@ -2022,29 +2005,6 @@ class GuiDocEditor(QPlainTextEdit):
return False return False
return True return True
def _checkDocSize(self, size: int) -> None:
"""Check if document size crosses the big document limit set in
config. If so, we will set the big document flag to True.
"""
bigLim = round(CONFIG.bigDocLimit*1000)
newState = size > bigLim
if newState != self._bigDoc:
if newState:
logger.info(
f"The document size is {size:n} > {bigLim:n}, "
f"big doc mode has been enabled"
)
else:
logger.info(
f"The document size is {size:n} <= {bigLim:n}, "
f"big doc mode has been disabled"
)
self._bigDoc = newState
return
def _autoSelect(self) -> QTextCursor: def _autoSelect(self) -> QTextCursor:
"""Return a cursor which may or may not have a selection based """Return a cursor which may or may not have a selection based
on user settings and document action. on user settings and document action.
@@ -58,7 +58,6 @@ showtabsnspaces = False
showlineendings = False showlineendings = False
showmultispaces = True showmultispaces = True
wordcounttimer = 5.0 wordcounttimer = 5.0
bigdoclimit = 800
incnoteswcount = True incnoteswcount = True
showfullpath = True showfullpath = True
highlightquotes = True highlightquotes = True
@@ -58,7 +58,6 @@ showtabsnspaces = True
showlineendings = True showlineendings = True
showmultispaces = True showmultispaces = True
wordcounttimer = 5.0 wordcounttimer = 5.0
bigdoclimit = 500
incnoteswcount = True incnoteswcount = True
showfullpath = False showfullpath = False
highlightquotes = False highlightquotes = False
@@ -159,9 +159,6 @@ def testDlgPreferences_Main(qtbot, monkeypatch, nwGUI, tstPaths):
qtbot.wait(KEY_DELAY) qtbot.wait(KEY_DELAY)
tabEditor.scrollPastEnd.setValue(0) tabEditor.scrollPastEnd.setValue(0)
qtbot.wait(KEY_DELAY)
tabEditor.bigDocLimit.setValue(500)
# Syntax Settings # Syntax Settings
qtbot.wait(KEY_DELAY) qtbot.wait(KEY_DELAY)
tabSyntax = nwPrefs.tabSyntax tabSyntax = nwPrefs.tabSyntax
-6
View File
@@ -104,7 +104,6 @@ def testGuiEditor_LoadText(qtbot, monkeypatch, caplog, nwGUI, projPath, ipsumTex
# Regular open # Regular open
assert nwGUI.docEditor.loadText(C.hSceneDoc) is True assert nwGUI.docEditor.loadText(C.hSceneDoc) is True
assert nwGUI.docEditor._bigDoc is False
# Reload too big text # Reload too big text
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
@@ -112,11 +111,6 @@ def testGuiEditor_LoadText(qtbot, monkeypatch, caplog, nwGUI, projPath, ipsumTex
assert nwGUI.docEditor.replaceText(longText) is False assert nwGUI.docEditor.replaceText(longText) is False
assert "The document you are trying to open is too big." in caplog.text assert "The document you are trying to open is too big." in caplog.text
# Big doc handling
CONFIG.bigDocLimit = 50
assert nwGUI.docEditor.loadText(C.hSceneDoc) is True
assert nwGUI.docEditor._bigDoc is True
# Regular open, with line number (1 indexed) # Regular open, with line number (1 indexed)
assert nwGUI.docEditor.loadText(C.hSceneDoc, tLine=4) is True assert nwGUI.docEditor.loadText(C.hSceneDoc, tLine=4) is True
cursPos = nwGUI.docEditor.getCursorPosition() cursPos = nwGUI.docEditor.getCursorPosition()