From 32052b1bc315316e91f7f17573c08d0a080476c4 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 17 Jun 2020 19:29:25 +0200 Subject: [PATCH] Searching through files can now loop back to first file again --- nw/gui/doceditor.py | 8 +++++--- nw/guimain.py | 16 +++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 382fc123..7873991f 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -1168,15 +1168,17 @@ class GuiDocEditor(QTextEdit): searchFor = self.docSearch.getSearchText() wasFound = self.find(searchFor, findOpt) if not wasFound: - if self.docSearch.doLoop: + if self.docSearch.doNextFile and not isBackward: + self.theParent.openNextDocument( + self.theHandle, wrapAround=self.docSearch.doLoop + ) + elif self.docSearch.doLoop: theCursor = self.textCursor() theCursor.movePosition( QTextCursor.End if isBackward else QTextCursor.Start ) self.setTextCursor(theCursor) self.find(searchFor, findOpt) - elif self.docSearch.doNextFile: - self.theParent.openNextDocument(self.theHandle) return diff --git a/nw/guimain.py b/nw/guimain.py index 1116f9aa..70a6ba0b 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -476,28 +476,34 @@ class GuiMain(QMainWindow): return False return True - def openNextDocument(self, tHandle): + def openNextDocument(self, tHandle, wrapAround=False): """Opens the next document in the project tree, following the document with the given handle. Stops when reaching the end. """ if self.hasProject: self.treeView.flushTreeOrder() - nHandle = None - goNext = False + nHandle = None # The next handle after tHandle + fHandle = None # The first file handle we encounter + foundIt = False # We've found tHandle, pick the next we see for tItem in self.theProject.projTree: if tItem is None: continue if tItem.itemType != nwItemType.FILE: continue + if fHandle is None: + fHandle = tItem.itemHandle if tItem.itemHandle == tHandle: - goNext = True - elif goNext: + foundIt = True + elif foundIt: nHandle = tItem.itemHandle break if nHandle is not None: self.openDocument(nHandle, tLine=0) return True + elif wrapAround: + self.openDocument(fHandle, tLine=0) + return False return False