Skip to content

Commit 3ba3ff8

Browse files
committed
fix(ui): restore Ctrl+Enter shortcut in bookmark dialog
The keyboard shortcut to submit the bookmark dialog was broken. Now uses the useHotkeys hook with enableOnInputs: true to properly handle Ctrl+Enter (or Cmd+Enter on Mac) from any field including textarea. https://claude.ai/code/session_01H5CR653mxrDbtqwK7aUA6G
1 parent 504e990 commit 3ba3ff8

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

src/components/bookmarks/BookmarkInlineCard.jsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { forwardRef, useRef, useEffect, useState } from 'react'
1+
import { forwardRef, useRef, useEffect, useState, useCallback } from 'react'
22
import { ExternalLink, Check, X } from 'lucide-react'
33
import { TagInput } from '../ui/TagInput'
44
import { Tag } from '../ui/Tag'
55
import { getAllTags, createBookmark, updateBookmark } from '../../services/bookmarks'
6+
import { useHotkeys } from '../../hooks/useHotkeys'
67

78
/**
89
* BookmarkInlineCard - Inline card for adding/editing bookmarks
@@ -110,7 +111,7 @@ export const BookmarkInlineCard = forwardRef(function BookmarkInlineCard(
110111
}
111112

112113
// Auto-save logic
113-
const saveChanges = () => {
114+
const saveChanges = useCallback(() => {
114115
const normalizedUrl = normalizeUrl(localUrl)
115116

116117
if (!validateUrl(localUrl)) {
@@ -143,7 +144,7 @@ export const BookmarkInlineCard = forwardRef(function BookmarkInlineCard(
143144
console.error('Failed to save bookmark:', error)
144145
return false
145146
}
146-
}
147+
}, [localUrl, localTitle, localDesc, localTags, localReadLater, isEditing, bookmark, onFieldChange, isNew])
147148

148149
const handleUrlBlur = () => {
149150
if (localUrl !== (bookmark?.url || '')) {
@@ -198,7 +199,7 @@ export const BookmarkInlineCard = forwardRef(function BookmarkInlineCard(
198199
handleTagsChange(newTags)
199200
}
200201

201-
const handleDone = () => {
202+
const handleDone = useCallback(() => {
202203
if (!validateUrl(localUrl)) {
203204
setUrlError('URL is required')
204205
urlInputRef.current?.focus()
@@ -208,12 +209,18 @@ export const BookmarkInlineCard = forwardRef(function BookmarkInlineCard(
208209
if (saveChanges()) {
209210
onDone?.()
210211
}
211-
}
212+
}, [localUrl, saveChanges, onDone])
212213

213214
const handleDiscard = () => {
214215
onDiscard?.()
215216
}
216217

218+
// Ctrl/Cmd+Enter to save from any field
219+
useHotkeys(
220+
{ 'mod+enter': handleDone },
221+
{ enableOnInputs: true }
222+
)
223+
217224
const handleKeyDown = (e, currentField) => {
218225
if (e.key === 'Escape') {
219226
e.preventDefault()
@@ -222,13 +229,6 @@ export const BookmarkInlineCard = forwardRef(function BookmarkInlineCard(
222229
return
223230
}
224231

225-
// Ctrl/Cmd+Enter saves from any field
226-
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
227-
e.preventDefault()
228-
handleDone()
229-
return
230-
}
231-
232232
// Tab navigation
233233
if (e.key === 'Tab') {
234234
e.preventDefault()

src/components/ui/Toast.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function Toast({ message, action, actionLabel = 'Undo', duration = 5000,
3232
<div
3333
className={cn(
3434
'fixed bottom-4 right-4 z-50',
35-
'flex items-center gap-3 px-4 py-3 rounded-lg shadow-lg',
35+
'flex items-center gap-4 px-4 py-3 rounded-lg shadow-lg',
3636
'bg-card border border-border text-foreground',
3737
'transition-all duration-150',
3838
isLeaving ? 'opacity-0 translate-y-2' : 'opacity-100 translate-y-0'
@@ -42,14 +42,14 @@ export function Toast({ message, action, actionLabel = 'Undo', duration = 5000,
4242
{action && (
4343
<button
4444
onClick={handleAction}
45-
className="text-sm font-medium text-primary hover:text-primary/80 transition-colors"
45+
className="text-sm font-medium text-primary hover:text-primary/80 transition-colors whitespace-nowrap"
4646
>
4747
{actionLabel}
4848
</button>
4949
)}
5050
<button
5151
onClick={handleClose}
52-
className="ml-1 p-1 rounded hover:bg-muted transition-colors"
52+
className="p-1 rounded hover:bg-muted transition-colors flex-shrink-0"
5353
aria-label="Dismiss"
5454
>
5555
<X className="w-4 h-4 text-muted-foreground" />

0 commit comments

Comments
 (0)