(e)
| 440 | }; |
| 441 | |
| 442 | const onKeyDown: KeyboardEventHandler<HTMLTextAreaElement> = async (e) => { |
| 443 | const isSpecialKey = e.ctrlKey || e.metaKey; |
| 444 | |
| 445 | if (isSpecialKey) { |
| 446 | switch (e.key) { |
| 447 | case 'b': { |
| 448 | e.preventDefault(); |
| 449 | return await getCommand().replaceWord( |
| 450 | getStyleReplacement('**'), |
| 451 | onUpdate, |
| 452 | ); |
| 453 | } |
| 454 | case 'i': { |
| 455 | e.preventDefault(); |
| 456 | return await getCommand().replaceWord( |
| 457 | getStyleReplacement('_'), |
| 458 | onUpdate, |
| 459 | ); |
| 460 | } |
| 461 | case 'k': { |
| 462 | e.preventDefault(); |
| 463 | e.stopPropagation(); |
| 464 | return await onLinkCommand?.(); |
| 465 | } |
| 466 | default: |
| 467 | break; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | const isSubmitting = |
| 472 | isSpecialKey && e.key === KeyboardCommand.Enter && input?.length; |
| 473 | |
| 474 | if (onSubmit && isSubmitting) { |
| 475 | return onSubmit(e); |
| 476 | } |
| 477 | |
| 478 | const isNavigatingPopup = |
| 479 | e.key === KeyboardCommand.Enter || |
| 480 | Y_AXIS_KEYS.includes(e.key as ArrowKey); |
| 481 | |
| 482 | const hasMentions = mentions?.length > 0; |
| 483 | const hasEmojis = !!emojiQuery; |
| 484 | |
| 485 | if (!isNavigatingPopup || (!hasMentions && !hasEmojis)) { |
| 486 | return e.stopPropagation(); // to stop app navigation |
| 487 | } |
| 488 | |
| 489 | e.preventDefault(); |
| 490 | |
| 491 | const arrowKey = e.key as ArrowKey; |
| 492 | |
| 493 | if (Y_AXIS_KEYS.includes(e.key as ArrowKey)) { |
| 494 | if (arrowKey === ArrowKey.Up) { |
| 495 | if (hasMentions) { |
| 496 | setSelected((selected - 1 + mentions.length) % mentions.length); |
| 497 | } else if (hasEmojis) { |
| 498 | setSelectedEmoji( |
| 499 | (selectedEmoji - 1 + emojiData.length) % emojiData.length, |
nothing calls this directly
no test coverage detected