Skip to content

Commit 977dfa4

Browse files
committed
don't capture kbd shortcuts when typing
1 parent 096586b commit 977dfa4

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

frontend/src/lib/components/ArticleCard.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import LinkContextMenu from '$lib/components/feed/LinkContextMenu.svelte';
5151
import { itemLabelsStore } from '$lib/stores/itemLabels.svelte';
5252
import { feedViewStore } from '$lib/stores/feedView.svelte';
53+
import { isInputFocused } from '$lib/stores/keyboard.svelte';
5354
import { sidebarStore } from '$lib/stores/sidebar.svelte';
5455
import { subscriptionsStore } from '$lib/stores/subscriptions.svelte';
5556
import { useParagraphTracking } from '$lib/hooks/useParagraphTracking.svelte';
@@ -748,6 +749,9 @@
748749
function handleParagraphKeydown(e: KeyboardEvent) {
749750
if (!expanded || paragraphTracking.totalParagraphs <= 1) return;
750751
if (e.metaKey || e.ctrlKey || e.altKey) return;
752+
// Don't hijack keys while typing in an input/textarea/contenteditable
753+
// (e.g. the share note box) — `h` must type, not toggle a highlight.
754+
if (isInputFocused()) return;
751755
752756
if (e.key === 'ArrowDown') {
753757
e.preventDefault();

frontend/src/lib/stores/keyboard.svelte.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ interface KeyboardState {
1414
shortcuts: Map<string, Shortcut>;
1515
}
1616

17+
/**
18+
* True when the user is typing into an editable element, so global keyboard
19+
* shortcuts (single letters like `h`, arrow keys, etc.) must not fire.
20+
* Shared by the central store and component-local window handlers.
21+
*/
22+
export function isInputFocused(): boolean {
23+
if (!browser) return false;
24+
const activeElement = document.activeElement;
25+
return (
26+
activeElement instanceof HTMLInputElement ||
27+
activeElement instanceof HTMLTextAreaElement ||
28+
activeElement?.getAttribute('contenteditable') === 'true'
29+
);
30+
}
31+
1732
function createKeyboardStore() {
1833
let state = $state<KeyboardState>({
1934
isHelpOpen: false,
@@ -34,16 +49,6 @@ function createKeyboardStore() {
3449
state.shortcuts.delete(shortcutKey);
3550
}
3651

37-
function isInputFocused(): boolean {
38-
if (!browser) return false;
39-
const activeElement = document.activeElement;
40-
return (
41-
activeElement instanceof HTMLInputElement ||
42-
activeElement instanceof HTMLTextAreaElement ||
43-
activeElement?.getAttribute('contenteditable') === 'true'
44-
);
45-
}
46-
4752
function handleKeydown(e: KeyboardEvent) {
4853
// Always allow Escape
4954
if (e.key === 'Escape') {

0 commit comments

Comments
 (0)