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." diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 0b2790cf..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 @@ -891,6 +903,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) @@ -1200,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 @@ -1399,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) @@ -1560,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 ##