Move focus upwards when pressing Escape
This commit is contained in:
parent
903d137cda
commit
5c6c607ea4
2 changed files with 14 additions and 0 deletions
|
|
@ -2,8 +2,18 @@
|
|||
import CNavbar from "./components/CNavbar.vue";
|
||||
import CNote from "./components/CNote.vue";
|
||||
import { useUiStore } from "./stores/ui";
|
||||
import { pathAncestor } from "./util";
|
||||
|
||||
const ui = useUiStore();
|
||||
|
||||
window.addEventListener("keypress", (ev) => {
|
||||
if (document.activeElement !== document.body) return;
|
||||
|
||||
if (ev.key === "Escape") {
|
||||
ui.focusPath = pathAncestor(ui.focusPath);
|
||||
return;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ export function pathAppend(path: string, segment: number): string {
|
|||
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[] {
|
||||
const parsedPath = pathParse(path);
|
||||
const result = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue