diff --git a/core/dropdowndiv.ts b/core/dropdowndiv.ts index 8a5cceabf..a1a254d03 100644 --- a/core/dropdowndiv.ts +++ b/core/dropdowndiv.ts @@ -156,6 +156,13 @@ export function setBoundsElement(boundsElem: Element|null) { boundsElement = boundsElem; } +/** + * @returns The field that currently owns this, or null. + */ +export function getOwner(): Field|null { + return owner; +} + /** * Provide the div for inserting content into the drop-down. * diff --git a/core/gesture.ts b/core/gesture.ts index c9578f45e..935aa37d8 100644 --- a/core/gesture.ts +++ b/core/gesture.ts @@ -22,6 +22,7 @@ import * as browserEvents from './browser_events.js'; import {BubbleDragger} from './bubble_dragger.js'; import * as common from './common.js'; import {config} from './config.js'; +import * as dropDownDiv from './dropdowndiv.js'; import * as eventUtils from './events/utils.js'; import type {Field} from './field.js'; import type {IBlockDragger} from './interfaces/i_block_dragger.js'; @@ -169,6 +170,14 @@ export class Gesture { /** Boolean for whether or not the workspace supports pinch-zoom. */ private isPinchZoomEnabled_: boolean|null = null; + /** + * The owner of the dropdownDiv when this gesture first starts. + * Needed because we'll close the dropdown before fields get to + * act on their events, and some fields care about who owns + * the dropdown. + */ + currentDropdownOwner: Field|null = null; + /** * @param e The event that kicked off this gesture. * @param creatorWorkspace The workspace that created this gesture and has a @@ -462,6 +471,9 @@ export class Gesture { // dragged, the block was moved, the parent workspace zoomed, etc. this.startWorkspace_.resize(); } + + // Keep track of which field owns the dropdown before we close it. + this.currentDropdownOwner = dropDownDiv.getOwner(); // Hide chaff also hides the flyout, so don't do it if the click is in a // flyout. this.startWorkspace_.hideChaff(!!this.flyout_); @@ -878,7 +890,13 @@ export class Gesture { 'Cannot do a field click because the start field is ' + 'undefined'); } - this.startField_.showEditor(this.mostRecentEvent_); + + // Only show the editor if the field's editor wasn't already open + // right before this gesture started. + const dropdownAlreadyOpen = this.currentDropdownOwner === this.startField_; + if (!dropdownAlreadyOpen) { + this.startField_.showEditor(this.mostRecentEvent_); + } this.bringBlockToFront_(); }