diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 134b2e1c..cfcb8409 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -1993,12 +1993,16 @@ class GuiDocEditor(QTextEdit): tInsert = nwUnicode.U_HELLIP tCheck = tInsert - if tCheck in self.mainConf.fmtPadBefore: + if self.mainConf.fmtPadBefore and tCheck in self.mainConf.fmtPadBefore: if self._allowSpaceBeforeColon(theText, tCheck): nDelete = max(nDelete, 1) + chkPos = thePos - nDelete - 1 + if chkPos >= 0 and theText[chkPos].isspace(): + # Strip existing space before inserting a new (#1061) + nDelete += 1 tInsert = self._typPadChar + tInsert - if tCheck in self.mainConf.fmtPadAfter: + if self.mainConf.fmtPadAfter and tCheck in self.mainConf.fmtPadAfter: if self._allowSpaceBeforeColon(theText, tCheck): nDelete = max(nDelete, 1) tInsert = tInsert + self._typPadChar diff --git a/tests/reference/guiEditor_Main_Final_000000000000f.nwd b/tests/reference/guiEditor_Main_Final_000000000000f.nwd index 1ac700fb..ab603231 100644 --- a/tests/reference/guiEditor_Main_Final_000000000000f.nwd +++ b/tests/reference/guiEditor_Main_Final_000000000000f.nwd @@ -35,6 +35,8 @@ Some “ double quoted text with spaces padded ”. Add space before this colon : See? +But don’t add a double space : See? + “Tab-indented text” >“Paragraph-indented text” diff --git a/tests/reference/guiEditor_Main_Final_nwProject.nwx b/tests/reference/guiEditor_Main_Final_nwProject.nwx index 5496b5b3..f61d3493 100644 --- a/tests/reference/guiEditor_Main_Final_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Final_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project New Novel @@ -17,8 +17,8 @@ None 0000000000008 0000000000008 - 145 - 118 + 153 + 126 27 @@ -59,7 +59,7 @@ New Chapter - + New Scene diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index b2e446bc..fd1218a0 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -439,6 +439,11 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) + for c in "But don't add a double space : See?": + qtbot.keyClick(nwGUI.docEditor, c, delay=typeDelay) + qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) + qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) + nwGUI.mainConf.fmtPadBefore = "" # Indent and Align