From 8d64a6672fffa936d02186658d97fa5c663d81c9 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 14 Oct 2020 13:43:18 +0200 Subject: [PATCH 1/3] Only apply format to the first block when multiple blocks are selected --- nw/config.py | 2 +- nw/gui/doceditor.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/nw/config.py b/nw/config.py index b4c14b27..675fad3d 100644 --- a/nw/config.py +++ b/nw/config.py @@ -955,4 +955,4 @@ class Config: return -# End Class Config +# END Class Config diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index b41fd764..67d80d40 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -1299,13 +1299,25 @@ class GuiDocEditor(QTextEdit): return theCursor def _toggleFormat(self, fLen, fChar): - """Toggle strikethrough text. + """Toggle the formatting of a specific type for a piece of text. + If more than one block is selected, the formatting is applied to + the first block. """ theCursor = self._autoSelect() if theCursor.hasSelection(): posS = theCursor.selectionStart() posE = theCursor.selectionEnd() + blockS = self.qDocument.findBlock(posS) + blockE = self.qDocument.findBlock(posE) + + if blockS != blockE: + posE = blockS.position() + blockS.length() - 1 + theCursor.clearSelection() + theCursor.setPosition(posS, QTextCursor.MoveAnchor) + theCursor.setPosition(posE, QTextCursor.KeepAnchor) + self.setTextCursor(theCursor) + numB = 0 for n in range(fLen): if self.qDocument.characterAt(posS-n-1) == fChar: From 1c27a8e0da844c44c54c7c8350dded6c7a41ef00 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 14 Oct 2020 14:13:59 +0200 Subject: [PATCH 2/3] Minor fix to the select word and select all functions --- nw/gui/doceditor.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 67d80d40..9ce47cbd 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -756,8 +756,8 @@ class GuiDocEditor(QTextEdit): * 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. + * The undo/redo/select all sequences bypasses the docAction + pathway from the menu, so we redirect them back from here. """ isReturn = keyEvent.key() == Qt.Key_Return isReturn |= keyEvent.key() == Qt.Key_Enter @@ -767,6 +767,8 @@ class GuiDocEditor(QTextEdit): self.docAction(nwDocAction.REDO) elif keyEvent == QKeySequence.Undo: self.docAction(nwDocAction.UNDO) + elif keyEvent == QKeySequence.SelectAll: + self.docAction(nwDocAction.SEL_ALL) else: QTextEdit.keyPressEvent(self, keyEvent) self.docFooter.updateLineCount() @@ -1292,10 +1294,11 @@ class GuiDocEditor(QTextEdit): reSelect = True if reSelect: theCursor.clearSelection() - theCursor.setPosition(posE-1) - theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, posE-posS-1) + theCursor.setPosition(posS, QTextCursor.MoveAnchor) + theCursor.setPosition(posE-1, QTextCursor.KeepAnchor) self.setTextCursor(theCursor) + return theCursor def _toggleFormat(self, fLen, fChar): @@ -1429,7 +1432,10 @@ class GuiDocEditor(QTextEdit): theCursor.clearSelection() theCursor.select(selMode) - if selMode == QTextCursor.BlockUnderCursor: + if selMode == QTextCursor.WordUnderCursor: + theCursor = self._autoSelect() + + elif selMode == QTextCursor.BlockUnderCursor: # This selection mode also selects the preceding oaragraph # separator, which we want to avoid. posS = theCursor.selectionStart() From 0dc07de77d5d3e865b43913b4a49789681b288b1 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 14 Oct 2020 18:20:41 +0200 Subject: [PATCH 3/3] Also handle multi-paragraph formatting for quotes --- nw/gui/doceditor.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 9ce47cbd..d5e3b045 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -1237,6 +1237,11 @@ class GuiDocEditor(QTextEdit): posS = theCursor.selectionStart() posE = theCursor.selectionEnd() + blockS = self.qDocument.findBlock(posS) + blockE = self.qDocument.findBlock(posE) + if blockS != blockE: + posE = blockS.position() + blockS.length() - 1 + theCursor.clearSelection() theCursor.beginEditBlock() theCursor.setPosition(posE) @@ -1245,8 +1250,8 @@ class GuiDocEditor(QTextEdit): theCursor.insertText(tBefore) theCursor.endEditBlock() - theCursor.setPosition(posE + len(tBefore)) - theCursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor, posE-posS) + theCursor.setPosition(posE + len(tBefore), QTextCursor.MoveAnchor) + theCursor.setPosition(posS + len(tBefore), QTextCursor.KeepAnchor) self.setTextCursor(theCursor) else: