diff --git a/nw/config.py b/nw/config.py index 675fad3d..993d657c 100644 --- a/nw/config.py +++ b/nw/config.py @@ -127,8 +127,8 @@ class Config: self.doReplaceDash = True self.doReplaceDots = True self.scrollPastEnd = True - self.scollWithCursor = False - self.scollToPoint = 40 + self.autoScroll = False + self.autoScrollPos = 30 self.wordCountTimer = 5.0 self.showTabsNSpaces = False @@ -465,11 +465,11 @@ class Config: self.scrollPastEnd = self._parseLine( cnfParse, cnfSec, "scrollpastend", self.CNF_BOOL, self.scrollPastEnd ) - self.scollWithCursor = self._parseLine( - cnfParse, cnfSec, "scollwithcursor", self.CNF_BOOL, self.scollWithCursor + self.autoScroll = self._parseLine( + cnfParse, cnfSec, "autoscroll", self.CNF_BOOL, self.autoScroll ) - self.scollToPoint = self._parseLine( - cnfParse, cnfSec, "scolltopoint", self.CNF_INT, self.scollToPoint + self.autoScrollPos = self._parseLine( + cnfParse, cnfSec, "autoscrollpos", self.CNF_INT, self.autoScrollPos ) self.fmtSingleQuotes = self._parseLine( cnfParse, cnfSec, "fmtsinglequote", self.CNF_LIST, self.fmtSingleQuotes @@ -616,8 +616,8 @@ class Config: cnfParse.set(cnfSec, "repdash", str(self.doReplaceDash)) cnfParse.set(cnfSec, "repdots", str(self.doReplaceDots)) cnfParse.set(cnfSec, "scrollpastend", str(self.scrollPastEnd)) - cnfParse.set(cnfSec, "scollwithcursor", str(self.scollWithCursor)) - cnfParse.set(cnfSec, "scolltopoint", str(self.scollToPoint)) + cnfParse.set(cnfSec, "autoscroll", str(self.autoScroll)) + cnfParse.set(cnfSec, "autoscrollpos", str(self.autoScrollPos)) cnfParse.set(cnfSec, "fmtsinglequote", self._packList(self.fmtSingleQuotes)) cnfParse.set(cnfSec, "fmtdoublequote", self._packList(self.fmtDoubleQuotes)) cnfParse.set(cnfSec, "spelltool", str(self.spellTool)) @@ -911,16 +911,21 @@ class Config: """ if cnfParse.has_section(cnfSec): if cnfParse.has_option(cnfSec, cnfName): - if cnfType == self.CNF_STR: - return cnfParse.get(cnfSec, cnfName) - elif cnfType == self.CNF_INT: - return cnfParse.getint(cnfSec, cnfName) - elif cnfType == self.CNF_BOOL: - return cnfParse.getboolean(cnfSec, cnfName) - elif cnfType == self.CNF_LIST: - return self._unpackList( - cnfParse.get(cnfSec, cnfName), len(cnfDefault), cnfDefault - ) + try: + if cnfType == self.CNF_STR: + return cnfParse.get(cnfSec, cnfName) + elif cnfType == self.CNF_INT: + return cnfParse.getint(cnfSec, cnfName) + elif cnfType == self.CNF_BOOL: + return cnfParse.getboolean(cnfSec, cnfName) + elif cnfType == self.CNF_LIST: + return self._unpackList( + cnfParse.get(cnfSec, cnfName), len(cnfDefault), cnfDefault + ) + except ValueError as e: + logger.error("Failed to load value from config file.") + logger.error(str(e)) + return cnfDefault def _checkNone(self, checkVal): diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 12b038ca..c6f0a0f4 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -778,7 +778,7 @@ class GuiDocEditor(QTextEdit): self.docAction(nwDocAction.SEL_ALL) return - if self.mainConf.scollWithCursor: + if self.mainConf.autoScroll: cOld = self.cursorRect().center().y() QTextEdit.keyPressEvent(self, keyEvent) @@ -789,7 +789,7 @@ class GuiDocEditor(QTextEdit): if okMod and okKey: cNew = self.cursorRect().center().y() cMov = cNew - cOld - mPos = self.mainConf.scollToPoint * self.viewport().height() * 0.01 + mPos = self.mainConf.autoScrollPos * self.viewport().height() * 0.01 if abs(cMov) > 0 and cOld > mPos: # Move the scroll bar vBar = self.verticalScrollBar() diff --git a/nw/gui/preferences.py b/nw/gui/preferences.py index 7b8e0905..945e35f6 100644 --- a/nw/gui/preferences.py +++ b/nw/gui/preferences.py @@ -569,23 +569,23 @@ class GuiConfigEditLayoutTab(QWidget): ) ## Typewriter Scrolling - self.scollWithCursor = QSwitch() - self.scollWithCursor.setChecked(self.mainConf.scollWithCursor) + self.autoScroll = QSwitch() + self.autoScroll.setChecked(self.mainConf.autoScroll) self.mainForm.addRow( "Typewriter style scrolling when you type", - self.scollWithCursor, + self.autoScroll, "Tries to keep the cursor at a fixed vertical position." ) ## Font Size - self.scollToPoint = QSpinBox(self) - self.scollToPoint.setMinimum(10) - self.scollToPoint.setMaximum(90) - self.scollToPoint.setSingleStep(1) - self.scollToPoint.setValue(self.mainConf.scollToPoint) + self.autoScrollPos = QSpinBox(self) + self.autoScrollPos.setMinimum(10) + self.autoScrollPos.setMaximum(90) + self.autoScrollPos.setSingleStep(1) + self.autoScrollPos.setValue(int(self.mainConf.autoScrollPos)) self.mainForm.addRow( - "Position in the editor to keep the cursor", - self.scollToPoint, + "Minimum position for Typewriter scrolling", + self.autoScrollPos, "In units of percentage of the editor height.", theUnit = "%" ) @@ -608,8 +608,8 @@ class GuiConfigEditLayoutTab(QWidget): textMargin = self.textMargin.value() tabWidth = self.tabWidth.value() scrollPastEnd = self.scrollPastEnd.isChecked() - scollWithCursor = self.scollWithCursor.isChecked() - scollToPoint = self.scollToPoint.value() + autoScroll = self.autoScroll.isChecked() + autoScrollPos = self.autoScrollPos.value() self.mainConf.textFont = textFont self.mainConf.textSize = textSize @@ -621,8 +621,8 @@ class GuiConfigEditLayoutTab(QWidget): self.mainConf.textMargin = textMargin self.mainConf.tabWidth = tabWidth self.mainConf.scrollPastEnd = scrollPastEnd - self.mainConf.scollWithCursor = scollWithCursor - self.mainConf.scollToPoint = scollToPoint + self.mainConf.autoScroll = autoScroll + self.mainConf.autoScrollPos = autoScrollPos self.mainConf.confChanged = True diff --git a/tests/reference/novelwriter.conf b/tests/reference/novelwriter.conf index bb141482..aef7459f 100644 --- a/tests/reference/novelwriter.conf +++ b/tests/reference/novelwriter.conf @@ -40,8 +40,8 @@ repdquotes = True repdash = True repdots = True scrollpastend = True -scollwithcursor = False -scolltopoint = 40 +autoscroll = False +autoscrollpos = 30 fmtsinglequote = ‘, ’ fmtdoublequote = “, ” spelltool = internal diff --git a/tests/reference/novelwriter_prefs.conf b/tests/reference/novelwriter_prefs.conf index ee591782..831bbf08 100644 --- a/tests/reference/novelwriter_prefs.conf +++ b/tests/reference/novelwriter_prefs.conf @@ -40,8 +40,8 @@ repdquotes = True repdash = True repdots = True scrollpastend = False -scollwithcursor = True -scolltopoint = 40 +autoscroll = True +autoscrollpos = 30 fmtsinglequote = ‘, ’ fmtdoublequote = “, ” spelltool = internal diff --git a/tests/test_dialogs.py b/tests/test_dialogs.py index ddc77738..abe14b64 100644 --- a/tests/test_dialogs.py +++ b/tests/test_dialogs.py @@ -1127,9 +1127,9 @@ def testPreferences(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp, nwRef, tmpC assert not tabLayout.scrollPastEnd.isChecked() qtbot.wait(keyDelay) - assert not tabLayout.scollWithCursor.isChecked() - qtbot.mouseClick(tabLayout.scollWithCursor, Qt.LeftButton) - assert tabLayout.scollWithCursor.isChecked() + assert not tabLayout.autoScroll.isChecked() + qtbot.mouseClick(tabLayout.autoScroll, Qt.LeftButton) + assert tabLayout.autoScroll.isChecked() # Editor Settings qtbot.wait(keyDelay) diff --git a/tests/test_gui.py b/tests/test_gui.py index ea7b54ec..0d9849d6 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -172,8 +172,8 @@ def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp): nwGUI.mainConf.hideHScroll = True nwGUI.mainConf.hideVScroll = True nwGUI.mainConf.scrollPastEnd = True - nwGUI.mainConf.scollToPoint = 80 - nwGUI.mainConf.scollWithCursor = True + nwGUI.mainConf.autoScrollPos = 80 + nwGUI.mainConf.autoScroll = True # Add a Character File nwGUI.setFocus(1)