Improved the emphasis function for alternating between levels
This commit is contained in:
+34
-5
@@ -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
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
|
||||
|
||||
+11
-11
@@ -1,21 +1,21 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<novelWriterXML appVersion="0.9.0rc1" hexVersion="0x000900c1" fileVersion="1.1" timeStamp="2020-06-12 17:13:30">
|
||||
<novelWriterXML appVersion="0.9.0rc1" hexVersion="0x000900c1" fileVersion="1.1" timeStamp="2020-06-12 22:46:53">
|
||||
<project>
|
||||
<name>Sample Project</name>
|
||||
<title>Sample Project</title>
|
||||
<author>Jane Smith</author>
|
||||
<author>Jay Doh</author>
|
||||
<saveCount>280</saveCount>
|
||||
<autoCount>41</autoCount>
|
||||
<editTime>4312</editTime>
|
||||
<saveCount>313</saveCount>
|
||||
<autoCount>47</autoCount>
|
||||
<editTime>5934</editTime>
|
||||
</project>
|
||||
<settings>
|
||||
<doBackup>False</doBackup>
|
||||
<spellCheck>True</spellCheck>
|
||||
<autoOutline>True</autoOutline>
|
||||
<lastEdited>bc0cbd2a407f3</lastEdited>
|
||||
<lastViewed>b3e74dbc1f584</lastViewed>
|
||||
<lastWordCount>920</lastWordCount>
|
||||
<lastEdited>636b6aa9b697b</lastEdited>
|
||||
<lastViewed>14298de4d9524</lastViewed>
|
||||
<lastWordCount>921</lastWordCount>
|
||||
<autoReplace>
|
||||
<A>B</A>
|
||||
<B>E</B>
|
||||
@@ -114,10 +114,10 @@
|
||||
<status>1st Draft</status>
|
||||
<exported>True</exported>
|
||||
<layout>SCENE</layout>
|
||||
<charCount>1199</charCount>
|
||||
<wordCount>216</wordCount>
|
||||
<charCount>1202</charCount>
|
||||
<wordCount>217</wordCount>
|
||||
<paraCount>7</paraCount>
|
||||
<cursorPos>950</cursorPos>
|
||||
<cursorPos>469</cursorPos>
|
||||
</item>
|
||||
<item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a">
|
||||
<name>Another Scene</name>
|
||||
@@ -129,7 +129,7 @@
|
||||
<charCount>476</charCount>
|
||||
<wordCount>93</wordCount>
|
||||
<paraCount>3</paraCount>
|
||||
<cursorPos>551</cursorPos>
|
||||
<cursorPos>428</cursorPos>
|
||||
</item>
|
||||
<item handle="ba8a28a246524" order="3" parent="e7ded148d6e4a">
|
||||
<name>Interlude</name>
|
||||
|
||||
Reference in New Issue
Block a user