Skip to content

Commit

Permalink
Better fragment handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jcreedcmu committed Mar 21, 2024
1 parent 4b09213 commit 32d187b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,19 @@ async function initTwelf(editor: EditorView) {
execCurrentBuffer();
};

if (window.location.hash) {
await resolveFragmentAction(await decode(window.location.hash.substring(1)));
// returns whether there was a hash at all
async function resolveCurrentFragmentAction(): Promise<boolean> {
if (window.location.hash) {
await resolveFragmentAction(await decode(window.location.hash.substring(1)));
return true;
}
return false;
}
else {

window.addEventListener('hashchange', resolveCurrentFragmentAction);

if (!(await resolveCurrentFragmentAction())) {
// if no fragment, then look to local storage for initial state
const savedElf = localStorage.getItem('savedElf');
if (savedElf != undefined) {
setText(savedElf);
Expand Down

0 comments on commit 32d187b

Please sign in to comment.