Skip to content

Commit 890f732

Browse files
committed
feat: Remove 'load' parameter from URL after loading content
1 parent 8e10e4c commit 890f732

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Editor.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,18 @@ export class Editor {
5959
const yamlContent = await response.text();
6060
this.ace.setValue(yamlContent, -1); // -1 moves cursor to the start
6161
console.log(`Loaded content from: ${loadUrl}`);
62-
// Optionally clear localStorage if loaded from URL to avoid conflict?
63-
// localStorage.removeItem(this.STORAGE_KEY);
62+
63+
// Remove the 'load' parameter from the URL without reloading
64+
const currentUrlParams = new URLSearchParams(window.location.search);
65+
currentUrlParams.delete('load');
66+
const newRelativePathQuery = window.location.pathname + (currentUrlParams.toString() ? '?' + currentUrlParams.toString() : '');
67+
window.history.replaceState({ path: newRelativePathQuery }, '', newRelativePathQuery);
6468
} catch (error) {
6569
console.error('Failed to load content from URL:', loadUrl, error);
70+
// Display error to the user in the output div and editor
71+
const errorMessage = `# Failed to load content from: ${loadUrl}\n# Error: ${error.message}`;
72+
this.output.innerHTML = `<div class="error">Failed to load content from <a href="${loadUrl}" target="_blank">${loadUrl}</a>: ${error.message}</div>`;
73+
this.ace.setValue(errorMessage, -1);
6674
}
6775
} else {
6876
// Load initial content from localStorage if no loadUrl

0 commit comments

Comments
 (0)