[studio] Fix navigate back not to iterate on the first item twice
All checks were successful
Build / build (push) Successful in 1m25s

This commit is contained in:
2025-08-09 14:57:11 -05:00
parent 870fb9c6e3
commit 8b50856149

View File

@@ -8,13 +8,18 @@ namespace studio {
void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept { void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept {
ox::String path = std::move(filePath); ox::String path = std::move(filePath);
if (beginsWith(path, "uuid://")) { if (keel::isUuidUrl(path)) {
auto const [p, err] = keel::uuidUrlToPath(keelCtx(ctx), path); auto const [p, err] = keel::uuidUrlToPath(keelCtx(ctx), path);
if (err) { if (err) {
return; return;
} }
path = p; path = p;
} }
//if (
// auto const [np, err] = ctx.navStack.back();
// !err && np->filePath == path && np->navArgs == navArgs.view()) {
// return;
//}
ctx.navStack.resize(ctx.navIdx + 1); ctx.navStack.resize(ctx.navIdx + 1);
ctx.navStack.emplace_back(ox::String{path}, ox::String{navArgs.view()}); ctx.navStack.emplace_back(ox::String{path}, ox::String{navArgs.view()});
try { try {
@@ -46,11 +51,14 @@ void navigateBack(Context &ctx) noexcept {
} }
break; break;
} }
oxDebugf("back: navIdx: {}", ctx.navIdx);
} }
void navigateForward(Context &ctx) noexcept { void navigateForward(Context &ctx) noexcept {
while (ctx.navIdx < ctx.navStack.size()) { oxDebugf("fwd 1: navIdx: {}", ctx.navIdx);
auto const &n = ctx.navStack[ctx.navIdx]; auto const nextIdx = ctx.navIdx + 1;
while (nextIdx < ctx.navStack.size()) {
auto const &n = ctx.navStack[nextIdx];
try { try {
ctx.navCallback(n.filePath, n.navArgs); ctx.navCallback(n.filePath, n.navArgs);
} catch (std::exception const &e) { } catch (std::exception const &e) {
@@ -58,12 +66,13 @@ void navigateForward(Context &ctx) noexcept {
oxErrf("navigateForward failed: {}", e.what()); oxErrf("navigateForward failed: {}", e.what());
} }
if (!ctx.project->exists(n.filePath)) { if (!ctx.project->exists(n.filePath)) {
std::ignore = ctx.navStack.erase(ctx.navIdx); std::ignore = ctx.navStack.erase(nextIdx);
continue; continue;
} }
++ctx.navIdx; ++ctx.navIdx;
break; break;
} }
oxDebugf("fwd 2: navIdx: {}", ctx.navIdx);
} }
} }