mirror of https://github.com/buster-so/buster.git
keyboard press stuff
This commit is contained in:
parent
c3041b548b
commit
8469471a45
|
@ -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}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue