Rebounce navigation events

This commit is contained in:
2026-01-30 12:26:36 +01:00
parent 5ce6b0c417
commit d3d26c6ae1
8 changed files with 56 additions and 26 deletions

View File

@@ -53,12 +53,19 @@ export class FSNavigator {
}
}
last_requested_path: string = ""
navigate = async (path: string, push_history: boolean) => {
if (path === this.last_requested_path) {
console.debug("FSNavigator: Requested path is equal to current path. Debouncing")
return
}
this.last_requested_path = path
if (path[0] !== "/") {
path = "/" + path
}
console.debug("Navigating to path", path, push_history)
console.debug("FSNavigator: Navigating to path", path, push_history)
try {
loading_start()

View File

@@ -69,7 +69,7 @@ const file_event: FileActionHandler = (action: FileAction, index: number, orig:
if (navigator.maxTouchPoints && navigator.maxTouchPoints > 0) {
select_node(index)
} else {
file_menu.open(nav.children[index], orig.target)
file_menu.open(nav.children[index], orig.target, orig)
}
break
case FileAction.Edit:
@@ -86,7 +86,7 @@ const file_event: FileActionHandler = (action: FileAction, index: number, orig:
select_node(index)
break
case FileAction.Menu:
file_menu.open(nav.children[index], orig.target)
file_menu.open(nav.children[index], orig.target, orig)
break
}
}

View File

@@ -19,16 +19,23 @@ let {
let dialog: Dialog = $state()
let node: FSNode = $state(null)
export const open = async (n: FSNode, target: EventTarget) => {
export const open = async (n: FSNode, target: EventTarget, event: Event) => {
node = n
let el: HTMLElement = (target as Element).closest("button")
if (el === null) {
el = (target as Element).closest("a")
}
// Wait for the view to update, so the dialog gets the proper measurements
await tick()
dialog.open(el.getBoundingClientRect())
let el: HTMLElement = (target as Element).closest("button")
if (el !== null) {
dialog.open(el.getBoundingClientRect())
return
}
if (event instanceof MouseEvent) {
dialog.open(event)
return
}
console.error("Cannot find suitable target for spawning dialog window")
}
const delete_node = async () => {