Move focus upwards when pressing Escape

This commit is contained in:
Joscha 2025-02-07 21:09:08 +01:00
parent 903d137cda
commit 5c6c607ea4
2 changed files with 14 additions and 0 deletions

View file

@ -2,8 +2,18 @@
import CNavbar from "./components/CNavbar.vue"; import CNavbar from "./components/CNavbar.vue";
import CNote from "./components/CNote.vue"; import CNote from "./components/CNote.vue";
import { useUiStore } from "./stores/ui"; import { useUiStore } from "./stores/ui";
import { pathAncestor } from "./util";
const ui = useUiStore(); const ui = useUiStore();
window.addEventListener("keypress", (ev) => {
if (document.activeElement !== document.body) return;
if (ev.key === "Escape") {
ui.focusPath = pathAncestor(ui.focusPath);
return;
}
});
</script> </script>
<template> <template>

View file

@ -11,6 +11,10 @@ export function pathAppend(path: string, segment: number): string {
return pathString(pathParse(path).concat(segment)); return pathString(pathParse(path).concat(segment));
} }
export function pathAncestor(path: string): string {
return pathString(pathParse(path).slice(0, -1));
}
export function pathAncestors(path: string): string[] { export function pathAncestors(path: string): string[] {
const parsedPath = pathParse(path); const parsedPath = pathParse(path);
const result = []; const result = [];