This commit is contained in:
@@ -30,33 +30,32 @@ void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs)
|
||||
}
|
||||
}
|
||||
|
||||
static void validateNavStack(Context &ctx, auto &navStack) noexcept {
|
||||
for (size_t i{}; i < navStack.size(); ++i) {
|
||||
auto const &n = navStack[i];
|
||||
if (!ctx.project->exists(n.filePath)) {
|
||||
std::ignore = navStack.erase(i);
|
||||
continue;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
void navigateBack(Context &ctx) noexcept {
|
||||
if (!ctx.navIdx) {
|
||||
return;
|
||||
}
|
||||
validateNavStack(ctx, ctx.navStack);
|
||||
auto &navIdx = *ctx.navIdx;
|
||||
navIdx = ox::min(navIdx, ctx.navStack.size() - 1);
|
||||
if (navIdx) {
|
||||
while (navIdx && navIdx < ctx.navStack.size()) {
|
||||
--navIdx;
|
||||
auto const &n = ctx.navStack[navIdx];
|
||||
// check for invalid entry
|
||||
if (!ctx.project->exists(n.filePath)) {
|
||||
// remove the invalid entry, then reset and retry
|
||||
auto const err = ctx.navStack.erase(navIdx);
|
||||
if (err.error) {
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// entry is valid, do the navigation
|
||||
try {
|
||||
ctx.navCallback(n.filePath, n.navArgs);
|
||||
} catch (std::exception const &e) {
|
||||
oxAssert(ctx.navCallback != nullptr, "navCallback is null");
|
||||
oxErrf("navigateForward failed: {}", e.what());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,16 +67,16 @@ void navigateForward(Context &ctx) noexcept {
|
||||
auto const nextIdx = navIdx + 1;
|
||||
while (nextIdx < ctx.navStack.size()) {
|
||||
auto const &n = ctx.navStack[nextIdx];
|
||||
if (!ctx.project->exists(n.filePath)) {
|
||||
std::ignore = ctx.navStack.erase(nextIdx);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
ctx.navCallback(n.filePath, n.navArgs);
|
||||
} catch (std::exception const &e) {
|
||||
oxAssert(ctx.navCallback != nullptr, "navCallback is null");
|
||||
oxErrf("navigateForward failed: {}", e.what());
|
||||
}
|
||||
if (!ctx.project->exists(n.filePath)) {
|
||||
std::ignore = ctx.navStack.erase(nextIdx);
|
||||
continue;
|
||||
}
|
||||
++navIdx;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user