push/popState is handled better

This commit is contained in:
Magnus Åhall 2026-05-03 09:51:48 +02:00
parent 9fc4a14ce3
commit 454d065baa
2 changed files with 21 additions and 17 deletions

View file

@ -30,6 +30,7 @@ export class App {
})
window.addEventListener('keydown', event => this.keyHandler(event))
window.addEventListener('popstate', event => this.popState(event))
document.getElementById('notes2').addEventListener('click', event => {
if (event.target.id === 'notes2')
document.getElementById('node-content')?.focus()
@ -114,6 +115,9 @@ export class App {
event.stopPropagation()
}
}//}}}
popState(event) {// {{{
_mbus.dispatch("GO_TO_NODE", { nodeUUID: event.state.nodeUUID, dontPush: true, dontExpand: true })
}// }}}
async getStartNode() {//{{{
let nodeUUID = ROOT_NODE
@ -181,7 +185,6 @@ export class App {
history.pushState({ nodeUUID }, '', `/notes2#${nodeUUID}`)
const node = nodeStore.node(nodeUUID)
node.reset() // any modifications are discarded.
this.currentNode = node
@ -246,6 +249,7 @@ class N2Crumb extends CustomHTMLElement {
this.elLink.href = `/notes2#${this.uuid}`
this.elLink.innerText = this.label
this.elLink.addEventListener('click', () => _mbus.dispatch("GO_TO_NODE", { nodeUUID: this.uuid, dontPush: false, dontExpand: true }))
}// }}}
}
customElements.define('n2-crumb', N2Crumb)