keyboard press stuff

This commit is contained in:
Nate Kelley 2025-09-29 11:38:03 -06:00
parent c3041b548b
commit 8469471a45
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
2 changed files with 16 additions and 13 deletions

View File

@ -95,26 +95,29 @@ export const BusterInput = ({
if (showSuggestionList && (event.key === 'ArrowUp' || event.key === 'ArrowDown')) { if (showSuggestionList && (event.key === 'ArrowUp' || event.key === 'ArrowDown')) {
commandListNavigatedRef.current = true; commandListNavigatedRef.current = true;
} }
// If Enter is pressed and command list was navigated, manually trigger selection
if (showSuggestionList && event.key === 'Enter' && commandListNavigatedRef.current) {
event.preventDefault();
event.stopPropagation();
// Find the currently selected item and trigger its click
const selectedItem = commandElement?.querySelector('[data-selected="true"]') as HTMLElement;
if (selectedItem) {
selectedItem.click();
}
}
}; };
const commandElement = commandRef.current; const commandElement = commandRef.current;
if (commandElement) { if (commandElement) {
commandElement.addEventListener('keydown', handleKeyDown); commandElement.addEventListener('keydown', handleKeyDown, true); // Use capture phase
return () => { return () => {
commandElement.removeEventListener('keydown', handleKeyDown); commandElement.removeEventListener('keydown', handleKeyDown, true);
}; };
} }
}, [showSuggestionList]); }, [showSuggestionList]);
return ( return (
<Command <Command ref={commandRef} value={value} label={ariaLabel} className="relative">
ref={commandRef}
value={value}
label={ariaLabel}
className="relative"
onValueChange={(v) => {
console.log('onValueChange', v);
}}
>
<BusterInputContainer <BusterInputContainer
onSubmit={onSubmitPreflight} onSubmit={onSubmitPreflight}
onStop={onStopPreflight} onStop={onStopPreflight}

View File

@ -15,9 +15,9 @@ export const SubmitOnEnter = ({
addKeyboardShortcuts() { addKeyboardShortcuts() {
return { return {
Enter: ({ editor }) => { Enter: ({ editor }) => {
// If command list has been navigated with arrow keys, let the command list handle Enter // If command list has been navigated, don't handle here - let the parent handle it
if (commandListNavigatedRef?.current) { if (commandListNavigatedRef?.current) {
return !!onPressEnter; // Let the command list handle this return !!onPressEnter;
} }
// Otherwise, let Tiptap handle the Enter key // Otherwise, let Tiptap handle the Enter key