From bdef9a39558ac8f38492d381067a6a8a0cf9eab4 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 30 Aug 2021 23:23:47 +0200 Subject: [PATCH] Fix smart quote issue (#874) --- nw/gui/doceditor.py | 12 ++++++-- .../guiEditor_Main_Final_0e17daca5f3e1.nwd | 12 ++++++++ .../guiEditor_Main_Final_nwProject.nwx | 18 +++++------ tests/test_gui/test_gui_guimain.py | 30 +++++++++++++++++++ 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index fdcba9b8..8aa0460f 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -1763,7 +1763,7 @@ class GuiDocEditor(QTextEdit): nDelete = 0 tInsert = theOne - if self.mainConf.doReplaceDQuote and theTwo == ' "': + if self.mainConf.doReplaceDQuote and theTwo[:1].isspace() and theTwo.endswith('"'): nDelete = 1 tInsert = self._typDQOpen @@ -1771,10 +1771,14 @@ class GuiDocEditor(QTextEdit): nDelete = 1 if thePos == 1: tInsert = self._typDQOpen + elif thePos == 2 and theTwo == '>"': + tInsert = self._typDQOpen + elif thePos == 3 and theThree == '>>"': + tInsert = self._typDQOpen else: tInsert = self._typDQClose - elif self.mainConf.doReplaceSQuote and theTwo == " '": + elif self.mainConf.doReplaceSQuote and theTwo[:1].isspace() and theTwo.endswith("'"): nDelete = 1 tInsert = self._typSQOpen @@ -1782,6 +1786,10 @@ class GuiDocEditor(QTextEdit): nDelete = 1 if thePos == 1: tInsert = self._typSQOpen + elif thePos == 2 and theTwo == ">'": + tInsert = self._typSQOpen + elif thePos == 3 and theThree == ">>'": + tInsert = self._typSQOpen else: tInsert = self._typSQClose diff --git a/tests/reference/guiEditor_Main_Final_0e17daca5f3e1.nwd b/tests/reference/guiEditor_Main_Final_0e17daca5f3e1.nwd index 65bcb039..0bd32fe8 100644 --- a/tests/reference/guiEditor_Main_Final_0e17daca5f3e1.nwd +++ b/tests/reference/guiEditor_Main_Final_0e17daca5f3e1.nwd @@ -27,3 +27,15 @@ This is another paragraph of much longer nonsense text. It is in fact 1 very ver ‘Full line single quoted text.’ + “Tab-indented text” + +>“Paragraph-indented text” + +>>“Right-aligned text” + + ‘Tab-indented text’ + +>‘Paragraph-indented text’ + +>>‘Right-aligned text’ + diff --git a/tests/reference/guiEditor_Main_Final_nwProject.nwx b/tests/reference/guiEditor_Main_Final_nwProject.nwx index 861888fa..4ced078d 100644 --- a/tests/reference/guiEditor_Main_Final_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Final_nwProject.nwx @@ -1,11 +1,11 @@ - + New Project - 4 + 5 2 - 8 + 5 True @@ -15,8 +15,8 @@ True 0e17daca5f3e1 None - 114 - 87 + 126 + 99 27 @@ -85,10 +85,10 @@ New True BOOK - 482 - 83 - 4 - 620 + 612 + 95 + 10 + 768 Plot diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index 8d363a3d..d15d25a6 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -286,6 +286,36 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir): qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) + for c in "\t\"Tab-indented text\"": + 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) + + for c in ">\"Paragraph-indented text\"": + 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) + + for c in ">>\"Right-aligned text\"": + 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) + + for c in "\t'Tab-indented text'": + 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) + + for c in ">'Paragraph-indented text'": + 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) + + for c in ">>'Right-aligned text'": + 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) + qtbot.wait(stepDelay) nwGUI.docEditor.wCounter.run() qtbot.wait(stepDelay)