Skip to content

Fix/simple mode submodel navigation#23

Merged
ellipse2v merged 2 commits intomainfrom
fix/simple-mode-submodel-navigation
Apr 19, 2026
Merged

Fix/simple mode submodel navigation#23
ellipse2v merged 2 commits intomainfrom
fix/simple-mode-submodel-navigation

Conversation

@ellipse2v
Copy link
Copy Markdown
Owner

When a project is loaded via the directory picker, all .md files are
opened as tabs with paths relative to the project root (e.g.
"components/database.md"). Sub-model links in the SVG carry the raw DSL
value (e.g. "./components/database.md" or "../components/database.md"),
which never matched the tab paths exactly, causing openOrSwitchToTab to
open a blank new tab instead of switching to the existing one. The blank
tab produced an empty SVG, which made svg-pan-zoom crash with a
non-finite SVGMatrix error.

Replace the single exact-path lookup with a three-stage search:

  1. Exact match on the raw or ./-stripped path
  2. Suffix match — handles ../ references where the tab path is rooted at
    the project directory but the DSL ref is relative to the current model
  3. Basename match — fallback when there is exactly one open tab with that
    filename (safe because multi-file projects rarely reuse filenames)

When projectLoaded is true and no match is found, return early with a
console warning instead of creating a blank tab (which would crash
svg-pan-zoom on the empty SVG). The blank-tab fallback is kept only for
server-managed mode where the user may legitimately start editing a new
sub-model.

Also defer svg-pan-zoom init to requestAnimationFrame with a cancellation
guard (_panZoomRafId) to prevent initialization on detached SVG elements
during rapid tab switches. All panZoomInstance.destroy() calls are
wrapped in try/catch to silence already-destroyed errors.

When a project is loaded via the directory picker, all .md files are
opened as tabs with paths relative to the project root (e.g.
"components/database.md"). Sub-model links in the SVG carry the raw DSL
value (e.g. "./components/database.md" or "../components/database.md"),
which never matched the tab paths exactly, causing openOrSwitchToTab to
open a blank new tab instead of switching to the existing one. The blank
tab produced an empty SVG, which made svg-pan-zoom crash with a
non-finite SVGMatrix error.

Replace the single exact-path lookup with a three-stage search:
1. Exact match on the raw or ./-stripped path
2. Suffix match — handles ../ references where the tab path is rooted at
   the project directory but the DSL ref is relative to the current model
3. Basename match — fallback when there is exactly one open tab with that
   filename (safe because multi-file projects rarely reuse filenames)

When projectLoaded is true and no match is found, return early with a
console warning instead of creating a blank tab (which would crash
svg-pan-zoom on the empty SVG). The blank-tab fallback is kept only for
server-managed mode where the user may legitimately start editing a new
sub-model.

Also defer svg-pan-zoom init to requestAnimationFrame with a cancellation
guard (_panZoomRafId) to prevent initialization on detached SVG elements
during rapid tab switches. All panZoomInstance.destroy() calls are
wrapped in try/catch to silence already-destroyed errors.
Path-based matching was unreliable: DSL refs are relative to the current
model file (./components/db.md) while tabs store project-root-relative
paths (components/db.md), and ../  refs make path normalization even
harder.

Simplify openOrSwitchToTab to extract only the filename (basename) from
the submodel href and compare it against the basename of every open tab's
path. This works regardless of directory nesting, ../ traversals, or
OS path separators.
@ellipse2v ellipse2v merged commit e5f8801 into main Apr 19, 2026
2 checks passed
@ellipse2v ellipse2v deleted the fix/simple-mode-submodel-navigation branch April 19, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant