Improved the emphasis function for alternating between levels
This commit is contained in:
+34
-5
@@ -942,7 +942,28 @@ class GuiDocEditor(QTextEdit):
|
|||||||
return theCursor
|
return theCursor
|
||||||
|
|
||||||
def _toggleEmph(self, eLevel):
|
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()
|
theCursor = self._autoSelect()
|
||||||
if theCursor.hasSelection():
|
if theCursor.hasSelection():
|
||||||
@@ -950,24 +971,32 @@ class GuiDocEditor(QTextEdit):
|
|||||||
posE = theCursor.selectionEnd()
|
posE = theCursor.selectionEnd()
|
||||||
|
|
||||||
numB = 0
|
numB = 0
|
||||||
for n in range(4):
|
for n in range(3):
|
||||||
if self.qDocument.characterAt(posS-n-1) == "*":
|
if self.qDocument.characterAt(posS-n-1) == "*":
|
||||||
numB += 1
|
numB += 1
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
numA = 0
|
numA = 0
|
||||||
for n in range(4):
|
for n in range(3):
|
||||||
if self.qDocument.characterAt(posE+n) == "*":
|
if self.qDocument.characterAt(posE+n) == "*":
|
||||||
numA += 1
|
numA += 1
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
cLevel = min(numB, numA)
|
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)
|
self._clearSurrounding(theCursor, eLevel)
|
||||||
|
elif cLevel == eLevel:
|
||||||
|
# Toggle mode, so clear what we had set
|
||||||
|
self._clearSurrounding(theCursor, cLevel)
|
||||||
else:
|
else:
|
||||||
self._wrapSelection("*"*(eLevel - cLevel))
|
# Already at 1 or 2, increase to 3
|
||||||
|
self._wrapSelection("*"*(3 - cLevel))
|
||||||
|
|
||||||
return
|
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.
|
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.
|
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
|
@location: Earth
|
||||||
|
|
||||||
This is a second scene in the same file as the previous scene. You can always split the files up later.
|
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'?>
|
<?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>
|
<project>
|
||||||
<name>Sample Project</name>
|
<name>Sample Project</name>
|
||||||
<title>Sample Project</title>
|
<title>Sample Project</title>
|
||||||
<author>Jane Smith</author>
|
<author>Jane Smith</author>
|
||||||
<author>Jay Doh</author>
|
<author>Jay Doh</author>
|
||||||
<saveCount>280</saveCount>
|
<saveCount>313</saveCount>
|
||||||
<autoCount>41</autoCount>
|
<autoCount>47</autoCount>
|
||||||
<editTime>4312</editTime>
|
<editTime>5934</editTime>
|
||||||
</project>
|
</project>
|
||||||
<settings>
|
<settings>
|
||||||
<doBackup>False</doBackup>
|
<doBackup>False</doBackup>
|
||||||
<spellCheck>True</spellCheck>
|
<spellCheck>True</spellCheck>
|
||||||
<autoOutline>True</autoOutline>
|
<autoOutline>True</autoOutline>
|
||||||
<lastEdited>bc0cbd2a407f3</lastEdited>
|
<lastEdited>636b6aa9b697b</lastEdited>
|
||||||
<lastViewed>b3e74dbc1f584</lastViewed>
|
<lastViewed>14298de4d9524</lastViewed>
|
||||||
<lastWordCount>920</lastWordCount>
|
<lastWordCount>921</lastWordCount>
|
||||||
<autoReplace>
|
<autoReplace>
|
||||||
<A>B</A>
|
<A>B</A>
|
||||||
<B>E</B>
|
<B>E</B>
|
||||||
@@ -114,10 +114,10 @@
|
|||||||
<status>1st Draft</status>
|
<status>1st Draft</status>
|
||||||
<exported>True</exported>
|
<exported>True</exported>
|
||||||
<layout>SCENE</layout>
|
<layout>SCENE</layout>
|
||||||
<charCount>1199</charCount>
|
<charCount>1202</charCount>
|
||||||
<wordCount>216</wordCount>
|
<wordCount>217</wordCount>
|
||||||
<paraCount>7</paraCount>
|
<paraCount>7</paraCount>
|
||||||
<cursorPos>950</cursorPos>
|
<cursorPos>469</cursorPos>
|
||||||
</item>
|
</item>
|
||||||
<item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a">
|
<item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a">
|
||||||
<name>Another Scene</name>
|
<name>Another Scene</name>
|
||||||
@@ -129,7 +129,7 @@
|
|||||||
<charCount>476</charCount>
|
<charCount>476</charCount>
|
||||||
<wordCount>93</wordCount>
|
<wordCount>93</wordCount>
|
||||||
<paraCount>3</paraCount>
|
<paraCount>3</paraCount>
|
||||||
<cursorPos>551</cursorPos>
|
<cursorPos>428</cursorPos>
|
||||||
</item>
|
</item>
|
||||||
<item handle="ba8a28a246524" order="3" parent="e7ded148d6e4a">
|
<item handle="ba8a28a246524" order="3" parent="e7ded148d6e4a">
|
||||||
<name>Interlude</name>
|
<name>Interlude</name>
|
||||||
|
|||||||
Reference in New Issue
Block a user