MCPcopy
hub / github.com/RaspberryPiFoundation/blockly / onHtmlInputKeyDown_

Function onHtmlInputKeyDown_

packages/blockly/core/field_input.ts:601–652  ·  view source on GitHub ↗

* Handle key down to the editor. * * @param e Keyboard event.

(e: KeyboardEvent)

Source from the content-addressed store, hash-verified

599 * @param e Keyboard event.
600 */
601 protected onHtmlInputKeyDown_(e: KeyboardEvent) {
602 if (e.key === 'Enter') {
603 WidgetDiv.hideIfOwner(this);
604 dropDownDiv.hideWithoutAnimation();
605 // Prevent this from also being handled by the Enter keyboard shortcut,
606 // which can re-show the field editor after we just dismissed it.
607 e.stopPropagation();
608 } else if (e.key === 'Escape') {
609 this.setValue(
610 this.htmlInput_!.getAttribute('data-untyped-default-value'),
611 false,
612 );
613 WidgetDiv.hideIfOwner(this);
614 dropDownDiv.hideWithoutAnimation();
615 } else if (e.key === 'Tab') {
616 e.preventDefault();
617 const navigator = this.workspace_?.getNavigator();
618
619 const isValidDestination = (node: IFocusableNode | null) =>
620 (node instanceof FieldInput ||
621 (node instanceof BlockSvg && node.isSimpleReporter())) &&
622 node !== this.getSourceBlock();
623
624 // eslint-disable-next-line @typescript-eslint/no-this-alias
625 let target: IFocusableNode | null | undefined = this;
626 do {
627 target = e.shiftKey
628 ? navigator?.getOutNode(target)
629 : navigator?.getInNode(target);
630 } while (target && !isValidDestination(target));
631 target =
632 target instanceof BlockSvg && target.isSimpleReporter()
633 ? target.getFields().next().value
634 : target;
635
636 if (target instanceof FieldInput) {
637 WidgetDiv.hideIfOwner(this);
638 dropDownDiv.hideWithoutAnimation();
639 const targetSourceBlock = target.getSourceBlock();
640 if (
641 target.isFullBlockField() &&
642 targetSourceBlock &&
643 targetSourceBlock instanceof BlockSvg
644 ) {
645 getFocusManager().focusNode(targetSourceBlock);
646 } else {
647 getFocusManager().focusNode(target);
648 }
649 target.showEditor();
650 }
651 }
652 }
653
654 /**
655 * Handle a change to the editor.

Callers

nothing calls this directly

Calls 10

isValidDestinationFunction · 0.85
getFocusManagerFunction · 0.85
isSimpleReporterMethod · 0.80
getFieldsMethod · 0.80
isFullBlockFieldMethod · 0.80
focusNodeMethod · 0.80
getNavigatorMethod · 0.65
getOutNodeMethod · 0.45
getInNodeMethod · 0.45
getSourceBlockMethod · 0.45

Tested by

no test coverage detected