From 4672bc444b058c9a5e4eb5a9c952c9cc0fb9974c Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sun, 24 May 2020 22:04:36 +0200 Subject: [PATCH 1/2] Fixed sorting bug for line numbers in index --- nw/core/index.py | 8 ++++---- nw/gui/elements/outline.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nw/core/index.py b/nw/core/index.py index 3633c841..e585a03a 100644 --- a/nw/core/index.py +++ b/nw/core/index.py @@ -354,7 +354,7 @@ class NWIndex(): else: return False - sTitle = "T%d" % nLine + sTitle = "T%06d" % nLine self.refIndex[tHandle][sTitle] = { "tags" : [], "updated" : time(), @@ -384,7 +384,7 @@ class NWIndex(): """Count text stats and save the counts to the index. """ cC, wC, pC = countWords(theText) - sTitle = "T%d" % nTitle + sTitle = "T%06d" % nTitle if isNovel: if tHandle in self.novelIndex: if sTitle in self.novelIndex[tHandle]: @@ -404,7 +404,7 @@ class NWIndex(): def _indexSynopsis(self, tHandle, isNovel, theText, nTitle): """Save the synopsis to the index. """ - sTitle = "T%d" % nTitle + sTitle = "T%06d" % nTitle if isNovel: if tHandle in self.novelIndex: if sTitle in self.novelIndex[tHandle]: @@ -425,7 +425,7 @@ class NWIndex(): if not isValid or len(theBits) == 0: return False - sTitle = "T%d" % nTitle + sTitle = "T%06d" % nTitle if sTitle not in self.refIndex[tHandle]: logger.error("Cannot save tags to file %s, no title %s" % (tHandle, sTitle)) return False diff --git a/nw/gui/elements/outline.py b/nw/gui/elements/outline.py index f09a38b6..7c196d2e 100644 --- a/nw/gui/elements/outline.py +++ b/nw/gui/elements/outline.py @@ -408,7 +408,7 @@ class GuiProjectOutline(QTreeWidget): newItem.setText(self.colIndex[nwOutline.HANDLE], tHandle) newItem.setText(self.colIndex[nwOutline.LEVEL], novIdx["level"]) newItem.setText(self.colIndex[nwOutline.LABEL], nwItem.itemName) - newItem.setText(self.colIndex[nwOutline.LINE], sTitle[1:]) + newItem.setText(self.colIndex[nwOutline.LINE], sTitle[1:].lstrip("0")) newItem.setText(self.colIndex[nwOutline.SYNOP], novIdx["synopsis"]) newItem.setText(self.colIndex[nwOutline.CCOUNT], str(novIdx["cCount"])) newItem.setText(self.colIndex[nwOutline.WCOUNT], str(novIdx["wCount"])) From b9ccd9418142276e5d6b4836b665c8900696b57f Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sun, 24 May 2020 22:12:40 +0200 Subject: [PATCH 2/2] Fix tests --- tests/test_project.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index a49cba7d..369c866d 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -156,7 +156,7 @@ def testIndexCheckThese(nwTempProj): "@pov: Jane" )) assert str(theIndex.tagIndex) == "{'Jane': [2, '2858dcd1057d3', 'CHARACTER']}" - assert theIndex.novelIndex[nHandle]["T1"]["title"] == "Hello World!" + assert theIndex.novelIndex[nHandle]["T000001"]["title"] == "Hello World!" assert str(theIndex.checkThese(["@tag", "Jane"], cItem)) == "[True, True]" assert str(theIndex.checkThese(["@tag", "John"], cItem)) == "[True, True]" @@ -196,10 +196,10 @@ def testIndexMeta(nwTempProj): "Well, not really.\n" )) assert str(theIndex.tagIndex) == "{'Jane': [2, '2858dcd1057d3', 'CHARACTER']}" - assert theIndex.novelIndex[nHandle]["T1"]["title"] == "Hello World!" + assert theIndex.novelIndex[nHandle]["T000001"]["title"] == "Hello World!" # The novel structure should contain the pointer to the novel file header - assert str(theIndex.getNovelStructure()) == "['41cfc0d1f2d12:T1']" + assert str(theIndex.getNovelStructure()) == "['41cfc0d1f2d12:T000001']" # The novel file should have the correct counts cC, wC, pC = theIndex.getCounts(nHandle)