diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index e77d89c2..26e64c82 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -942,7 +942,28 @@ class GuiDocEditor(QTextEdit): return theCursor def _toggleEmph(self, eLevel): - """Toggle emphasis of a given level. + """Toggle emphasis of a given level between 1 and 3, where 1 is + italic, 2 is bold, and 3 is bold italic. The current level in + the text is cLevel. The rules are as follows: + + cLevel | eLevel | Result + ============+============+============ + None | Italic | Italic + None | Bold | Bold + None | BoldItalic | BoldItalic + ------------+------------+------------ + Italic | Italic | None + Italic | Bold | BoldItalic + Italic | BoldItalic | BoldItalic + ------------+------------+------------ + Bold | Italic | BoldItalic + Bold | Bold | None + Bold | BoldItalic | BoldItalic + ------------+------------+------------ + BoldItalic | Italic | Bold + BoldItalic | Bold | Italic + BoldItalic | BoldItalic | None + """ theCursor = self._autoSelect() if theCursor.hasSelection(): @@ -950,24 +971,32 @@ class GuiDocEditor(QTextEdit): posE = theCursor.selectionEnd() numB = 0 - for n in range(4): + for n in range(3): if self.qDocument.characterAt(posS-n-1) == "*": numB += 1 else: break numA = 0 - for n in range(4): + for n in range(3): if self.qDocument.characterAt(posE+n) == "*": numA += 1 else: break cLevel = min(numB, numA) - if cLevel == eLevel: + if cLevel == 0: + # Has no emphasis, set to desired level + self._wrapSelection("*"*eLevel) + elif cLevel == 3: + # Has max, so reduce by desired level self._clearSurrounding(theCursor, eLevel) + elif cLevel == eLevel: + # Toggle mode, so clear what we had set + self._clearSurrounding(theCursor, cLevel) else: - self._wrapSelection("*"*(eLevel - cLevel)) + # Already at 1 or 2, increase to 3 + self._wrapSelection("*"*(3 - cLevel)) return diff --git a/sample/content/636b6aa9b697b.nwd b/sample/content/636b6aa9b697b.nwd index e93bbb57..7b2d92c6 100644 --- a/sample/content/636b6aa9b697b.nwd +++ b/sample/content/636b6aa9b697b.nwd @@ -7,7 +7,7 @@ A scene is defined by a level three heading, like the one at the top of this page. The scene will be assigned to the chapter preceding it in the project tree. -Each paragraph in the scene is separated by a blank line. The text supports minimal formatting, like **bold**, _italic_ and __underscore__. +Each paragraph in the scene is separated by a blank line. The text supports minimal formatting, like **bold**, *italic* and ***bold italic***. In addition, the editor supports automatic formatting of “quotes”, both double and ‘single’. Depending on the syntax highlighter, these can be in different colours. diff --git a/sample/content/bc0cbd2a407f3.nwd b/sample/content/bc0cbd2a407f3.nwd index 94b036c0..4a099dfc 100644 --- a/sample/content/bc0cbd2a407f3.nwd +++ b/sample/content/bc0cbd2a407f3.nwd @@ -14,6 +14,3 @@ In fact, if you wish, you can add all the scenes in the chapter file too. All no @location: Earth This is a second scene in the same file as the previous scene. You can always split the files up later. - - - diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index cee9b2fa..0a34f9ff 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,21 +1,21 @@ - + Sample Project Sample Project Jane Smith Jay Doh - 280 - 41 - 4312 + 313 + 47 + 5934 False True True - bc0cbd2a407f3 - b3e74dbc1f584 - 920 + 636b6aa9b697b + 14298de4d9524 + 921 B E @@ -114,10 +114,10 @@ 1st Draft True SCENE - 1199 - 216 + 1202 + 217 7 - 950 + 469 Another Scene @@ -129,7 +129,7 @@ 476 93 3 - 551 + 428 Interlude