Cursor position is now saved and loaded with the document.

This commit is contained in:
Veronica K. B. Olsen
2019-05-18 13:52:45 +02:00
parent cb71da5200
commit 19b2521b73
4 changed files with 26 additions and 3 deletions
+10
View File
@@ -120,6 +120,16 @@ class GuiDocEditor(QTextEdit):
theText = self.toPlainText() theText = self.toPlainText()
return theText return theText
def setCursorPosition(self, thePosition):
theCursor = self.textCursor()
theCursor.setPosition(thePosition)
self.setTextCursor(theCursor)
return True
def getCursorPosition(self):
theCursor = self.textCursor()
return theCursor.position()
## ##
# Spell Checking # Spell Checking
## ##
+4
View File
@@ -206,15 +206,19 @@ class GuiMain(QMainWindow):
self.saveDocument() self.saveDocument()
self.stackPane.setCurrentIndex(self.stackDoc) self.stackPane.setCurrentIndex(self.stackDoc)
self.docEditor.setText(self.theDocument.openDocument(tHandle)) self.docEditor.setText(self.theDocument.openDocument(tHandle))
self.docEditor.setCursorPosition(self.theDocument.theItem.cursorPos)
self.docEditor.changeWidth() self.docEditor.changeWidth()
self.docEditor.setFocus()
return True return True
def saveDocument(self): def saveDocument(self):
if self.theDocument.theItem is not None: if self.theDocument.theItem is not None:
docHtml = self.docEditor.getText() docHtml = self.docEditor.getText()
cursPos = self.docEditor.getCursorPosition()
self.theDocument.theItem.setCharCount(self.docEditor.charCount) self.theDocument.theItem.setCharCount(self.docEditor.charCount)
self.theDocument.theItem.setWordCount(self.docEditor.wordCount) self.theDocument.theItem.setWordCount(self.docEditor.wordCount)
self.theDocument.theItem.setParaCount(self.docEditor.paraCount) self.theDocument.theItem.setParaCount(self.docEditor.paraCount)
self.theDocument.theItem.setCursorPos(cursPos)
self.theDocument.saveDocument(docHtml) self.theDocument.saveDocument(docHtml)
self.docEditor.setDocumentChanged(False) self.docEditor.setDocumentChanged(False)
return True return True
@@ -13,7 +13,7 @@ Some text here would look good as well, and maybe some "dialogue"?
So, this is some __text__ that weve been adding to this document. It is utterly meaningless text, _but_ since this is just dummy text, that doesnt really matter. The text is perfectly happy to live in this document reggardless. So, this is some __text__ that weve been adding to this document. It is utterly meaningless text, _but_ since this is just dummy text, that doesnt really matter. The text is perfectly happy to live in this document reggardless.
This paragraph is also meaningless. At least a bit. This paragraph is also meaningless. At least a bit.
# #
## ##
+11 -2
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.1.0" fileVersion="1.0" timeStamp="2019-05-12 16:22:26"> <novelWriterXML appVersion="0.1.2" fileVersion="1.0" timeStamp="2019-05-18 13:47:34">
<project> <project>
<name>Sample Project</name> <name>Sample Project</name>
<title>Sample Project</title> <title>Sample Project</title>
@@ -27,6 +27,7 @@
<charCount>23</charCount> <charCount>23</charCount>
<wordCount>5</wordCount> <wordCount>5</wordCount>
<paraCount>1</paraCount> <paraCount>1</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="e7ded148d6e4a" order="1" parent="7031beac91f75"> <item handle="e7ded148d6e4a" order="1" parent="7031beac91f75">
<name>Some Chapter</name> <name>Some Chapter</name>
@@ -45,6 +46,7 @@
<charCount>2571</charCount> <charCount>2571</charCount>
<wordCount>377</wordCount> <wordCount>377</wordCount>
<paraCount>5</paraCount> <paraCount>5</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="636b6aa9b697b" order="1" parent="e7ded148d6e4a"> <item handle="636b6aa9b697b" order="1" parent="e7ded148d6e4a">
<name>File With Stuff</name> <name>File With Stuff</name>
@@ -53,9 +55,10 @@
<status>1</status> <status>1</status>
<expanded>False</expanded> <expanded>False</expanded>
<layout>SCENE</layout> <layout>SCENE</layout>
<charCount>417</charCount> <charCount>405</charCount>
<wordCount>71</wordCount> <wordCount>71</wordCount>
<paraCount>5</paraCount> <paraCount>5</paraCount>
<cursorPos>421</cursorPos>
</item> </item>
<item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a"> <item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a">
<name>New File</name> <name>New File</name>
@@ -67,6 +70,7 @@
<charCount>69</charCount> <charCount>69</charCount>
<wordCount>17</wordCount> <wordCount>17</wordCount>
<paraCount>1</paraCount> <paraCount>1</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="f6622b4617424" order="1" parent="None"> <item handle="f6622b4617424" order="1" parent="None">
<name>Characters</name> <name>Characters</name>
@@ -92,6 +96,7 @@
<charCount>42</charCount> <charCount>42</charCount>
<wordCount>8</wordCount> <wordCount>8</wordCount>
<paraCount>1</paraCount> <paraCount>1</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="bb2c23b3c42cc" order="1" parent="f7e2d9f330615"> <item handle="bb2c23b3c42cc" order="1" parent="f7e2d9f330615">
<name>Jane Smith</name> <name>Jane Smith</name>
@@ -103,6 +108,7 @@
<charCount>51</charCount> <charCount>51</charCount>
<wordCount>9</wordCount> <wordCount>9</wordCount>
<paraCount>1</paraCount> <paraCount>1</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="73eee34351f85" order="2" parent="None"> <item handle="73eee34351f85" order="2" parent="None">
<name>Locations</name> <name>Locations</name>
@@ -121,6 +127,7 @@
<charCount>66</charCount> <charCount>66</charCount>
<wordCount>13</wordCount> <wordCount>13</wordCount>
<paraCount>1</paraCount> <paraCount>1</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="f75dac270c2a7" order="3" parent="None"> <item handle="f75dac270c2a7" order="3" parent="None">
<name>Trash</name> <name>Trash</name>
@@ -139,6 +146,7 @@
<charCount>0</charCount> <charCount>0</charCount>
<wordCount>0</wordCount> <wordCount>0</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
<item handle="879437bde105e" order="1" parent="f75dac270c2a7"> <item handle="879437bde105e" order="1" parent="f75dac270c2a7">
<name>New File</name> <name>New File</name>
@@ -150,6 +158,7 @@
<charCount>0</charCount> <charCount>0</charCount>
<wordCount>0</wordCount> <wordCount>0</wordCount>
<paraCount>0</paraCount> <paraCount>0</paraCount>
<cursorPos>0</cursorPos>
</item> </item>
</content> </content>
</novelWriterXML> </novelWriterXML>