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')) {
|
||||
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;
|
||||
if (commandElement) {
|
||||
commandElement.addEventListener('keydown', handleKeyDown);
|
||||
commandElement.addEventListener('keydown', handleKeyDown, true); // Use capture phase
|
||||
return () => {
|
||||
commandElement.removeEventListener('keydown', handleKeyDown);
|
||||
commandElement.removeEventListener('keydown', handleKeyDown, true);
|
||||
};
|
||||
}
|
||||
}, [showSuggestionList]);
|
||||
|
||||
return (
|
||||
<Command
|
||||
ref={commandRef}
|
||||
value={value}
|
||||
label={ariaLabel}
|
||||
className="relative"
|
||||
onValueChange={(v) => {
|
||||
console.log('onValueChange', v);
|
||||
}}
|
||||
>
|
||||
<Command ref={commandRef} value={value} label={ariaLabel} className="relative">
|
||||
<BusterInputContainer
|
||||
onSubmit={onSubmitPreflight}
|
||||
onStop={onStopPreflight}
|
||||
|
|
|
@ -15,9 +15,9 @@ export const SubmitOnEnter = ({
|
|||
addKeyboardShortcuts() {
|
||||
return {
|
||||
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) {
|
||||
return !!onPressEnter; // Let the command list handle this
|
||||
return !!onPressEnter;
|
||||
}
|
||||
|
||||
// Otherwise, let Tiptap handle the Enter key
|
||||
|
|
Loading…
Reference in New Issue