mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-08 03:08:29 +02:00

* Extract bookmark view contexts * Implement basic partial updates for bookmark list and tag cloud * Refactor confirm button JS into web component * Refactor bulk edit JS into web component * Refactor tag autocomplete JS into web component * Refactor bookmark page JS into web component * Refactor global shortcuts JS into web component * Update tests * Add E2E test for partial updates * Add partial updates for archived bookmarks * Add partial updates for shared bookmarks * Cleanup helpers * Improve naming in bulk edit * Refactor shared components into behaviors * Refactor bulk edit components into behaviors * Refactor bookmark list components into behaviors * Update tests * Combine all scripts into bundle * Fix E2E CI
74 lines
1.9 KiB
JavaScript
74 lines
1.9 KiB
JavaScript
import { registerBehavior } from "./index";
|
|
|
|
class GlobalShortcuts {
|
|
constructor() {
|
|
document.addEventListener("keydown", this.onKeyDown.bind(this));
|
|
}
|
|
|
|
onKeyDown(event) {
|
|
// Skip if event occurred within an input element
|
|
const targetNodeName = event.target.nodeName;
|
|
const isInputTarget =
|
|
targetNodeName === "INPUT" ||
|
|
targetNodeName === "SELECT" ||
|
|
targetNodeName === "TEXTAREA";
|
|
|
|
if (isInputTarget) {
|
|
return;
|
|
}
|
|
|
|
// Handle shortcuts for navigating bookmarks with arrow keys
|
|
const isArrowUp = event.key === "ArrowUp";
|
|
const isArrowDown = event.key === "ArrowDown";
|
|
if (isArrowUp || isArrowDown) {
|
|
event.preventDefault();
|
|
|
|
// Detect current bookmark list item
|
|
const path = event.composedPath();
|
|
const currentItem = path.find(
|
|
(item) => item.hasAttribute && item.hasAttribute("ld-bookmark-item"),
|
|
);
|
|
|
|
// Find next item
|
|
let nextItem;
|
|
if (currentItem) {
|
|
nextItem = isArrowUp
|
|
? currentItem.previousElementSibling
|
|
: currentItem.nextElementSibling;
|
|
} else {
|
|
// Select first item
|
|
nextItem = document.querySelector("[ld-bookmark-item]");
|
|
}
|
|
// Focus first link
|
|
if (nextItem) {
|
|
nextItem.querySelector("a").focus();
|
|
}
|
|
}
|
|
|
|
// Handle shortcut for toggling all notes
|
|
if (event.key === "e") {
|
|
const list = document.querySelector(".bookmark-list");
|
|
if (list) {
|
|
list.classList.toggle("show-notes");
|
|
}
|
|
}
|
|
|
|
// Handle shortcut for focusing search input
|
|
if (event.key === "s") {
|
|
const searchInput = document.querySelector('input[type="search"]');
|
|
|
|
if (searchInput) {
|
|
searchInput.focus();
|
|
event.preventDefault();
|
|
}
|
|
}
|
|
|
|
// Handle shortcut for adding new bookmark
|
|
if (event.key === "n") {
|
|
window.location.assign("/bookmarks/new");
|
|
}
|
|
}
|
|
}
|
|
|
|
registerBehavior("ld-global-shortcuts", GlobalShortcuts);
|