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 {
|
void navigateBack(Context &ctx) noexcept {
|
||||||
if (!ctx.navIdx) {
|
if (!ctx.navIdx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
validateNavStack(ctx, ctx.navStack);
|
|
||||||
auto &navIdx = *ctx.navIdx;
|
auto &navIdx = *ctx.navIdx;
|
||||||
navIdx = ox::min(navIdx, ctx.navStack.size() - 1);
|
navIdx = ox::min(navIdx, ctx.navStack.size() - 1);
|
||||||
if (navIdx) {
|
while (navIdx && navIdx < ctx.navStack.size()) {
|
||||||
--navIdx;
|
--navIdx;
|
||||||
auto const &n = ctx.navStack[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 {
|
try {
|
||||||
ctx.navCallback(n.filePath, n.navArgs);
|
ctx.navCallback(n.filePath, n.navArgs);
|
||||||
} catch (std::exception const &e) {
|
} catch (std::exception const &e) {
|
||||||
oxAssert(ctx.navCallback != nullptr, "navCallback is null");
|
oxAssert(ctx.navCallback != nullptr, "navCallback is null");
|
||||||
oxErrf("navigateForward failed: {}", e.what());
|
oxErrf("navigateForward failed: {}", e.what());
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,16 +67,16 @@ void navigateForward(Context &ctx) noexcept {
|
|||||||
auto const nextIdx = navIdx + 1;
|
auto const nextIdx = navIdx + 1;
|
||||||
while (nextIdx < ctx.navStack.size()) {
|
while (nextIdx < ctx.navStack.size()) {
|
||||||
auto const &n = ctx.navStack[nextIdx];
|
auto const &n = ctx.navStack[nextIdx];
|
||||||
|
if (!ctx.project->exists(n.filePath)) {
|
||||||
|
std::ignore = ctx.navStack.erase(nextIdx);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
ctx.navCallback(n.filePath, n.navArgs);
|
ctx.navCallback(n.filePath, n.navArgs);
|
||||||
} catch (std::exception const &e) {
|
} catch (std::exception const &e) {
|
||||||
oxAssert(ctx.navCallback != nullptr, "navCallback is null");
|
oxAssert(ctx.navCallback != nullptr, "navCallback is null");
|
||||||
oxErrf("navigateForward failed: {}", e.what());
|
oxErrf("navigateForward failed: {}", e.what());
|
||||||
}
|
}
|
||||||
if (!ctx.project->exists(n.filePath)) {
|
|
||||||
std::ignore = ctx.navStack.erase(nextIdx);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
++navIdx;
|
++navIdx;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user