MCPcopy Create free account
hub / github.com/dailydotdev/apps / onKeyDown

Function onKeyDown

packages/shared/src/hooks/input/useMarkdownInput.ts:444–526  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

getStyleReplacementFunction · 0.90
onLinkCommandFunction · 0.85
onApplyMentionFunction · 0.85
onApplyEmojiFunction · 0.85
replaceWordMethod · 0.80
onSubmitFunction · 0.50

Tested by

no test coverage detected