From 0acea8877a73db97eaa367f10963ea7b69271d9d Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sun, 16 Aug 2020 13:15:25 +0200 Subject: [PATCH 1/3] Added the option to replace 3 hypens with emdash, not just endash+hyphen --- nw/gui/doceditor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 0b2790cf..b455be7f 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -891,6 +891,10 @@ class GuiDocEditor(QTextEdit): else: theCursor.insertText(self.typSQClose) + elif self.mainConf.doReplaceDash and theThree == "---": + theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 3) + theCursor.insertText(nwUnicode.U_EMDASH) + elif self.mainConf.doReplaceDash and theTwo == "--": theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, 2) theCursor.insertText(nwUnicode.U_ENDASH) From 3f6737a3b82c9cb9d9d39d171ee2dbc72540584b Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sun, 16 Aug 2020 14:27:20 +0200 Subject: [PATCH 2/3] Better capture of the tab, return and enter keys in the editor and search function --- nw/gui/doceditor.py | 49 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index b455be7f..f41e67a8 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -641,24 +641,36 @@ class GuiDocEditor(QTextEdit): def keyPressEvent(self, keyEvent): """Intercept key press events. We need to intercept a few key sequences: - * The return key redirects here even if the search box has - focus. Since we need the return key to continue search, we - block any further interaction here while it's in focus. - * The undo sequence bypasses the doAction pathway from the - menu, so we redirect it back from here. - * The default redo sequence is Ctrl+Shift+Z, which we don't - use, so we block it. + * The return and enter key redirects here even if the search + box has focus. Since we need these keys to continue search, + we block any further interaction here while it's in focus. + * The undo/redo sequences bypasses the doAction pathway from + the menu, so we redirect them back from here. """ - if self.docSearch.searchBox.hasFocus(): + isReturn = keyEvent.key() == Qt.Key_Return + isReturn |= keyEvent.key() == Qt.Key_Enter + if isReturn and self.docSearch.searchBox.hasFocus(): return elif keyEvent == QKeySequence.Redo: - return + self.docAction(nwDocAction.REDO) elif keyEvent == QKeySequence.Undo: self.docAction(nwDocAction.UNDO) else: QTextEdit.keyPressEvent(self, keyEvent) return + def focusNextPrevChild(self, toNext): + """Capture the focus request from the tab key on the text + editor. If the editor has focus, we do not change focus and + allow the editor to insert a tab. If the search bar has focus, + we forward the call to the search object. + """ + if self.hasFocus(): + return False + elif self.docSearch.isVisible(): + return self.docSearch.cycleFocus(toNext) + return True + def mouseReleaseEvent(self, mEvent): """If the mouse button is released and the control key is pressed, check if we're clicking on a tag, and trigger the @@ -1204,6 +1216,8 @@ class GuiDocEditor(QTextEdit): theCursor = self.textCursor() if theCursor.hasSelection(): self.docSearch.setSearchText(theCursor.selectedText()) + else: + self.docSearch.setSearchText(None) self.docSearch.setReplaceText("") self.updateDocMargins() return @@ -1403,12 +1417,12 @@ class GuiDocEditSearch(QFrame): # Text Boxes # ========== - self.searchBox = QLineEdit() + self.searchBox = QLineEdit(self) self.searchBox.setFont(boxFont) self.searchBox.setPlaceholderText("Search") self.searchBox.returnPressed.connect(self._doSearch) - self.replaceBox = QLineEdit() + self.replaceBox = QLineEdit(self) self.replaceBox.setFont(boxFont) self.replaceBox.setPlaceholderText("Replace") self.replaceBox.returnPressed.connect(self._doSearch) @@ -1564,6 +1578,19 @@ class GuiDocEditSearch(QFrame): return + def cycleFocus(self, toNext): + """The tab key just alternates focus between the two input + boxes, if the replace box is visible. + """ + if self.replaceBox.isVisible(): + if self.searchBox.hasFocus(): + self.replaceBox.setFocus(True) + return True + elif self.replaceBox.hasFocus(): + self.searchBox.setFocus(True) + return True + return False + ## # Get and Set Functions ## From fa1c79a1da0f371acd7d916fe7398bbdd2976e26 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sun, 16 Aug 2020 14:28:04 +0200 Subject: [PATCH 3/3] Add the alternative redo sequence Ctrl+Shift+Z to the documentation --- docs/source/interface.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/interface.rst b/docs/source/interface.rst index 5d5f8114..770b7d59 100644 --- a/docs/source/interface.rst +++ b/docs/source/interface.rst @@ -350,6 +350,7 @@ Most features are available as keyboard shortcuts. These are as follows: ":kbd:`Ctrl`:kbd:`Shift`:kbd:`R`", "Close the document viewer." ":kbd:`Ctrl`:kbd:`Shift`:kbd:`S`", "Save the current project." ":kbd:`Ctrl`:kbd:`Shift`:kbd:`W`", "Close the current project." + ":kbd:`Ctrl`:kbd:`Shift`:kbd:`Z`", "Alternative sequence for redo last undo." ":kbd:`Ctrl`:kbd:`Shift`:kbd:`Up`", "Move item one step up in the project tree." ":kbd:`Ctrl`:kbd:`Shift`:kbd:`Down`", "Move item one step down in the project tree." ":kbd:`F1`", "Open the documentation. This will either open the Qt Assistant, if available, or send you to the documentation website."