* Handle key down to the editor. * * @param e Keyboard event.
(e: KeyboardEvent)
| 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. |
nothing calls this directly
no test coverage detected