Skip to content

Commit

Permalink
Fix view URL redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
justvanrossum committed Jan 14, 2025
1 parent 944b81a commit 8f291ed
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/fontra/client/core/fontra-menus.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { registerActionInfo } from "./actions.js";
import * as html from "./html-utils.js";
import { translate } from "./localization.js";
import { assert } from "./utils.js";
import { MenuBar } from "/web-components/menu-bar.js";
import { MenuItemDivider } from "/web-components/menu-panel.js";

Expand Down Expand Up @@ -166,7 +167,7 @@ function getFontMenuItems() {
enabled: () => enabled,
callback: () => {
const url = new URL(window.location);
url.pathname = `/fontinfo/-/${url.pathname.split("/").slice(-1)[0]}`;
url.pathname = rerouteViewPath(url.pathname, "fontinfo");
url.hash = panelID;
window.open(url.toString());
},
Expand All @@ -184,7 +185,7 @@ function getWindowMenuItems() {
enabled: () => true,
callback: () => {
const url = new URL(window.location);
url.pathname = `/fontoverview/-/${url.pathname.split("/").slice(-1)[0]}`;
url.pathname = rerouteViewPath(url.pathname, "fontoverview");
url.hash = ""; // remove any hash
window.open(url.toString());
},
Expand All @@ -194,14 +195,23 @@ function getWindowMenuItems() {
enabled: () => true,
callback: () => {
const url = new URL(window.location);
url.pathname = `/editor/-/${url.pathname.split("/").slice(-1)[0]}`;
url.pathname = rerouteViewPath(url.pathname, "editor");
url.hash = ""; // remove any hash
window.open(url.toString());
},
},
];
}

function rerouteViewPath(path, targetView) {
assert(path[0] === "/");
const parts = path.split("/");
assert(parts.length >= 3);
assert(parts[1].length > 0);
parts[1] = targetView;
return parts.join("/");
}

// Default action infos

{
Expand Down

0 comments on commit 8f291ed

Please sign in to comment.