Skip to content

Commit

Permalink
fix(gui): don't crash when navigating back to a file that has been re…
Browse files Browse the repository at this point in the history
…moved
  • Loading branch information
craftablescience committed Feb 26, 2024
1 parent ae4955d commit bb4e651
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/gui/FileViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,29 @@ void NavBar::setPath(const QString& newPath) {
}

void NavBar::navigateBack() {
if (this->historyIndex > 0) {
auto oldIndex = this->historyIndex;
do {
if (this->historyIndex == 0) {
return;
}
this->historyIndex--;
} while (!this->window->hasEntry(this->history.at(this->historyIndex)));

if (oldIndex != this->historyIndex) {
this->processPathChanged(this->history.at(this->historyIndex), false);
}
}

void NavBar::navigateNext() {
if (this->historyIndex < this->history.size() - 1) {
auto oldIndex = this->historyIndex;
do {
if (this->historyIndex == this->history.size() - 1) {
return;
}
this->historyIndex++;
} while (!this->window->hasEntry(this->history.at(this->historyIndex)));

if (oldIndex != this->historyIndex) {
this->processPathChanged(this->history.at(this->historyIndex), false);
}
}
Expand Down

0 comments on commit bb4e651

Please sign in to comment.