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] 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: