Skip to content

Commit

Permalink
Scroll novel view when looping through documents (#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Nov 29, 2023
1 parent ef93b41 commit ce666d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions novelwriter/gui/noveltree.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,27 +567,25 @@ def setLastColSize(self, colSize: int) -> None:
self._lastColSize = minmax(colSize, 15, 75)/100.0
return

def setActiveHandle(self, tHandle: str | None) -> None:
def setActiveHandle(self, tHandle: str | None, doScroll: bool = False) -> None:
"""Highlight the rows associated with a given handle."""
tStart = time()

didScroll = False
self._actHandle = tHandle
for i in range(self.topLevelItemCount()):
tItem = self.topLevelItem(i)
if tItem is not None:
if tItem := self.topLevelItem(i):
if tItem.data(self.C_DATA, self.D_HANDLE) == tHandle:
tItem.setBackground(self.C_TITLE, self.palette().alternateBase())
tItem.setBackground(self.C_WORDS, self.palette().alternateBase())
tItem.setBackground(self.C_EXTRA, self.palette().alternateBase())
tItem.setBackground(self.C_MORE, self.palette().alternateBase())
if doScroll and not didScroll:
self.scrollToItem(tItem, QAbstractItemView.ScrollHint.PositionAtCenter)
didScroll = True
else:
tItem.setBackground(self.C_TITLE, self.palette().base())
tItem.setBackground(self.C_WORDS, self.palette().base())
tItem.setBackground(self.C_EXTRA, self.palette().base())
tItem.setBackground(self.C_MORE, self.palette().base())

logger.debug("Highlighted Novel Tree in %.3f ms", (time() - tStart)*1000)

return

##
Expand Down
2 changes: 1 addition & 1 deletion novelwriter/guimain.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def openDocument(self, tHandle: str | None, tLine: int | None = None,
if self.docEditor.loadText(tHandle, tLine):
SHARED.project.data.setLastHandle(tHandle, "editor")
self.projView.setSelectedHandle(tHandle, doScroll=doScroll)
self.novelView.setActiveHandle(tHandle)
self.novelView.setActiveHandle(tHandle, doScroll=doScroll)
if changeFocus:
self.docEditor.setFocus()
else:
Expand Down

0 comments on commit ce666d9

Please sign in to comment.