Back-references not consideres all tags in a document, not just the first one
This commit is contained in:
+8
-9
@@ -260,9 +260,9 @@ class NWIndex():
|
||||
logger.debug("Indexing item with handle %s" % tHandle)
|
||||
|
||||
# Check file type, and reset its old index
|
||||
# Also add a dummy entry for T0 in case the file has no title
|
||||
# Also add a dummy entry T000000 in case the file has no title
|
||||
self.refIndex[tHandle] = {}
|
||||
self.refIndex[tHandle]["T0"] = {
|
||||
self.refIndex[tHandle]["T000000"] = {
|
||||
"tags" : [],
|
||||
"updated" : time(),
|
||||
}
|
||||
@@ -606,18 +606,17 @@ class NWIndex():
|
||||
if tHandle is None:
|
||||
return theRefs
|
||||
|
||||
theTag = None
|
||||
theTags = []
|
||||
for tTag in self.tagIndex:
|
||||
if tHandle == self.tagIndex[tTag][1]:
|
||||
theTag = tTag
|
||||
break
|
||||
theTags.append(tTag)
|
||||
|
||||
if theTag is not None:
|
||||
if theTags:
|
||||
for tHandle in self.refIndex:
|
||||
for sTitle in self.refIndex[tHandle]:
|
||||
for nLine, tKey, tTag in self.refIndex[tHandle][sTitle]["tags"]:
|
||||
if tTag == theTag:
|
||||
theRefs[tHandle] = nLine
|
||||
for _, _, tTag in self.refIndex[tHandle][sTitle]["tags"]:
|
||||
if tTag in theTags and tHandle not in theRefs:
|
||||
theRefs[tHandle] = sTitle
|
||||
|
||||
return theRefs
|
||||
|
||||
|
||||
@@ -395,6 +395,8 @@ class GuiDocEditor(QTextEdit):
|
||||
def setCursorPosition(self, thePosition):
|
||||
"""Move the cursor to a given position in the document.
|
||||
"""
|
||||
if not isinstance(thePosition, int):
|
||||
return False
|
||||
if thePosition >= 0:
|
||||
theCursor = self.textCursor()
|
||||
theCursor.setPosition(thePosition)
|
||||
@@ -410,12 +412,13 @@ class GuiDocEditor(QTextEdit):
|
||||
def setCursorLine(self, theLine):
|
||||
"""Move the cursor to a given line in the document.
|
||||
"""
|
||||
if theLine is None:
|
||||
if not isinstance(theLine, int):
|
||||
return False
|
||||
if theLine >= 0:
|
||||
theBlock = self.qDocument.findBlockByLineNumber(theLine)
|
||||
if theBlock:
|
||||
self.setCursorPosition(theBlock.position())
|
||||
logger.verbose("Cursor moved to line %d" % theLine)
|
||||
return True
|
||||
|
||||
##
|
||||
|
||||
@@ -206,6 +206,33 @@ class GuiDocViewer(QTextBrowser):
|
||||
self.docTitle.setTitleFromHandle(self.theHandle)
|
||||
return
|
||||
|
||||
##
|
||||
# Setters
|
||||
##
|
||||
|
||||
def setCursorPosition(self, thePosition):
|
||||
"""Move the cursor to a given position in the document.
|
||||
"""
|
||||
if not isinstance(thePosition, int):
|
||||
return False
|
||||
if thePosition >= 0:
|
||||
theCursor = self.textCursor()
|
||||
theCursor.setPosition(thePosition)
|
||||
self.setTextCursor(theCursor)
|
||||
return True
|
||||
|
||||
def setCursorLine(self, theLine):
|
||||
"""Move the cursor to a given line in the document.
|
||||
"""
|
||||
if not isinstance(theLine, int):
|
||||
return False
|
||||
if theLine >= 0:
|
||||
theBlock = self.qDocument.findBlockByLineNumber(theLine)
|
||||
if theBlock:
|
||||
self.setCursorPosition(theBlock.position())
|
||||
logger.verbose("Cursor moved to line %d" % theLine)
|
||||
return True
|
||||
|
||||
##
|
||||
# Events
|
||||
##
|
||||
|
||||
@@ -107,7 +107,11 @@ class GuiDocViewDetails(QWidget):
|
||||
for tHandle in theRefs:
|
||||
tItem = self.theProject.projTree[tHandle]
|
||||
if tItem is not None:
|
||||
theList.append("<a href='#tag=%s'>%s</a>" % (tHandle,tItem.itemName))
|
||||
theList.append("<a href='#tag=%s:%s'>%s</a>" % (
|
||||
tHandle, theRefs[tHandle], tItem.itemName
|
||||
))
|
||||
|
||||
# print(theList)
|
||||
|
||||
self.refList.setText(", ".join(theList))
|
||||
self.refList.adjustSize()
|
||||
@@ -122,9 +126,15 @@ class GuiDocViewDetails(QWidget):
|
||||
"""Capture the link-click and forward it to the document viewer
|
||||
class for handling.
|
||||
"""
|
||||
if len(theLink) == 18:
|
||||
tHandle = theLink[-13:]
|
||||
self.theParent.viewDocument(tHandle)
|
||||
logger.verbose("Clicked link: '%s'" % theLink)
|
||||
if len(theLink) == 26:
|
||||
tHandle = theLink[5:18]
|
||||
tLine = theLink[19:26]
|
||||
if tLine[1:].isdigit():
|
||||
nLine = int(tLine[1:])
|
||||
else:
|
||||
nLine = 1
|
||||
self.theParent.viewDocument(tHandle, nLine)
|
||||
return
|
||||
|
||||
def _doShowHide(self, chState):
|
||||
|
||||
+10
-8
@@ -485,7 +485,7 @@ class GuiMain(QMainWindow):
|
||||
self.docEditor.saveText()
|
||||
return True
|
||||
|
||||
def viewDocument(self, tHandle=None):
|
||||
def viewDocument(self, tHandle=None, nLine=0):
|
||||
"""Load a document for viewing in the view panel.
|
||||
"""
|
||||
if tHandle is None:
|
||||
@@ -503,13 +503,15 @@ class GuiMain(QMainWindow):
|
||||
# Make sure main tab is in Editor view
|
||||
self.tabWidget.setCurrentWidget(self.splitView)
|
||||
|
||||
if self.docViewer.loadText(tHandle) and not self.viewPane.isVisible():
|
||||
bPos = self.splitMain.sizes()
|
||||
self.viewPane.setVisible(True)
|
||||
vPos = [0,0]
|
||||
vPos[0] = int(bPos[1]/2)
|
||||
vPos[1] = bPos[1]-vPos[0]
|
||||
self.splitView.setSizes(vPos)
|
||||
if self.docViewer.loadText(tHandle):
|
||||
if not self.viewPane.isVisible():
|
||||
bPos = self.splitMain.sizes()
|
||||
self.viewPane.setVisible(True)
|
||||
vPos = [0,0]
|
||||
vPos[0] = int(bPos[1]/2)
|
||||
vPos[1] = bPos[1]-vPos[0]
|
||||
self.splitView.setSizes(vPos)
|
||||
self.docViewer.setCursorLine(nLine)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
### We Found John!
|
||||
|
||||
@pov: John
|
||||
@location: Mars
|
||||
@location: Mars, OuterSpace
|
||||
|
||||
Jane has been searching for a while, and she finally found John on Mars. He was indeed in space! What was he doing on Mars anyway? Well, it turns out, he was farming potatoes.
|
||||
|
||||
@@ -5,4 +5,10 @@
|
||||
|
||||
Space … it’s an awful lot of nothing, with bits in it here and there. Some of which, people like to call home.
|
||||
|
||||
## Outer Space
|
||||
|
||||
@tag: OuterSpace
|
||||
|
||||
Now even further into space!
|
||||
|
||||
You can have more than one tag in a file, as long as there is only one tag per heading.
|
||||
|
||||
+11
-11
@@ -1,5 +1,5 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<novelWriterXML appVersion="0.6" hexVersion="0x000600f0" fileVersion="1.0" saveCount="168" autoCount="26" timeStamp="2020-05-24 18:33:34">
|
||||
<novelWriterXML appVersion="0.6.1" hexVersion="0x000601f0" fileVersion="1.0" saveCount="182" autoCount="34" timeStamp="2020-05-25 21:08:45">
|
||||
<project>
|
||||
<name>Sample Project</name>
|
||||
<title>Sample Project</title>
|
||||
@@ -10,9 +10,9 @@
|
||||
<settings>
|
||||
<spellCheck>True</spellCheck>
|
||||
<autoOutline>True</autoOutline>
|
||||
<lastEdited>636b6aa9b697b</lastEdited>
|
||||
<lastViewed>ba8a28a246524</lastViewed>
|
||||
<lastWordCount>914</lastWordCount>
|
||||
<lastEdited>ae7339df26ded</lastEdited>
|
||||
<lastViewed>ae7339df26ded</lastViewed>
|
||||
<lastWordCount>941</lastWordCount>
|
||||
<autoReplace>
|
||||
<A>B</A>
|
||||
<B>E</B>
|
||||
@@ -73,7 +73,7 @@
|
||||
<expanded>False</expanded>
|
||||
<exported>True</exported>
|
||||
<layout>PAGE</layout>
|
||||
<charCount>208</charCount>
|
||||
<charCount>210</charCount>
|
||||
<wordCount>40</wordCount>
|
||||
<paraCount>2</paraCount>
|
||||
<cursorPos>213</cursorPos>
|
||||
@@ -174,7 +174,7 @@
|
||||
<charCount>139</charCount>
|
||||
<wordCount>28</wordCount>
|
||||
<paraCount>1</paraCount>
|
||||
<cursorPos>343</cursorPos>
|
||||
<cursorPos>237</cursorPos>
|
||||
</item>
|
||||
<item handle="ae7339df26ded" order="6" parent="e7ded148d6e4a">
|
||||
<name>We Found John!</name>
|
||||
@@ -187,7 +187,7 @@
|
||||
<charCount>189</charCount>
|
||||
<wordCount>37</wordCount>
|
||||
<paraCount>1</paraCount>
|
||||
<cursorPos>224</cursorPos>
|
||||
<cursorPos>236</cursorPos>
|
||||
</item>
|
||||
<item handle="f6622b4617424" order="1" parent="None">
|
||||
<name>Characters</name>
|
||||
@@ -257,10 +257,10 @@
|
||||
<expanded>False</expanded>
|
||||
<exported>True</exported>
|
||||
<layout>NOTE</layout>
|
||||
<charCount>115</charCount>
|
||||
<wordCount>24</wordCount>
|
||||
<paraCount>1</paraCount>
|
||||
<cursorPos>133</cursorPos>
|
||||
<charCount>241</charCount>
|
||||
<wordCount>51</wordCount>
|
||||
<paraCount>3</paraCount>
|
||||
<cursorPos>286</cursorPos>
|
||||
</item>
|
||||
<item handle="5eaea4e8cdee8" order="2" parent="15c4492bd5107">
|
||||
<name>Mars</name>
|
||||
|
||||
Reference in New Issue
Block a user