From 9400d52ee95a8f56947061170c7757ee20692a21 Mon Sep 17 00:00:00 2001 From: Kerwin Bryant Date: Tue, 14 Jan 2025 03:36:19 +0000 Subject: [PATCH] fix --- .../features/repo-view-file-tree-sidebar.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/web_src/js/features/repo-view-file-tree-sidebar.ts b/web_src/js/features/repo-view-file-tree-sidebar.ts index e97741ad33..de65dcc517 100644 --- a/web_src/js/features/repo-view-file-tree-sidebar.ts +++ b/web_src/js/features/repo-view-file-tree-sidebar.ts @@ -96,4 +96,29 @@ export async function initViewFileTreeSidebar() { loadContent(); }}); fileTreeView.mount(fileTree); + + window.addEventListener('popstate', () => { + selectedItem.value = extractPath(window.location.href); + loadContent(); + }); +} + +function extractPath(url) { + // Create a URL object + const urlObj = new URL(url); + + // Get the pathname part + const path = urlObj.pathname; + + // Define a regular expression to match "/{param1}/{param2}/src/{branch}/{main}/" + const regex = /^\/[^\/]+\/[^\/]+\/src\/[^\/]+\/[^\/]+\//; + + // Use RegExp#exec() method to match the path + const match = regex.exec(path); + if (match) { + return path.substring(match[0].length); + } + + // If the path does not match, return the original path + return path; }