From a5847c64d4663d0411055497016c87b7af2517a0 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Thu, 17 Feb 2022 18:04:28 -0800 Subject: [PATCH] Add workaround for error update --- .../src/components/ActionDispatcher.ts | 7 +++++ .../mindplot/src/components/CommandContext.ts | 1 - .../src/components/MultilineTextEditor.ts | 28 ++++++++++++------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/packages/mindplot/src/components/ActionDispatcher.ts b/packages/mindplot/src/components/ActionDispatcher.ts index 8130c3d8..fc813521 100644 --- a/packages/mindplot/src/components/ActionDispatcher.ts +++ b/packages/mindplot/src/components/ActionDispatcher.ts @@ -30,9 +30,16 @@ import Topic from './Topic'; abstract class ActionDispatcher extends Events { private static _instance: ActionDispatcher; + private _commandContext: CommandContext; + constructor(commandContext: CommandContext) { $assert(commandContext, 'commandContext can not be null'); super(); + this._commandContext = commandContext; + } + + getCommandContext(): CommandContext { + return this._commandContext; } abstract addRelationship(model: RelationshipModel, mindmap: Mindmap): void; diff --git a/packages/mindplot/src/components/CommandContext.ts b/packages/mindplot/src/components/CommandContext.ts index c1dd485e..549d1306 100644 --- a/packages/mindplot/src/components/CommandContext.ts +++ b/packages/mindplot/src/components/CommandContext.ts @@ -40,7 +40,6 @@ class CommandContext { this._designer = value; } - /** */ findTopics(topicIds: number[]): Topic[] { $assert($defined(topicIds), 'topicsIds can not be null'); const topicsIds = Array.isArray(topicIds) ? topicIds : [topicIds]; diff --git a/packages/mindplot/src/components/MultilineTextEditor.ts b/packages/mindplot/src/components/MultilineTextEditor.ts index beddbe93..381dcf3c 100644 --- a/packages/mindplot/src/components/MultilineTextEditor.ts +++ b/packages/mindplot/src/components/MultilineTextEditor.ts @@ -22,6 +22,7 @@ import initHotKeyPluggin from '../../../../libraries/jquery.hotkeys'; import Events from './Events'; import ActionDispatcher from './ActionDispatcher'; import Topic from './Topic'; +import { Designer } from '..'; initHotKeyPluggin($); @@ -255,18 +256,25 @@ class MultilineTextEditor extends Events { close(update: boolean): void { if (this.isVisible() && this._topic) { if (!$defined(update) || update) { - this._updateModel(); + const actionDispatcher = ActionDispatcher.getInstance(); + // Workaround. For some reason, close is triggered but the topic has been removed. Temporally, try to validate if exits. + try { + actionDispatcher + .getCommandContext() + .findTopics([this._topic.getId()]); + this._updateModel(); + + // Let make the visible text in the node ... + this._topic.getTextShape().setVisibility(true); + } catch (e) { + console.log(e); + } + // Remove it form the screen ... + this._containerElem.remove(); + this._containerElem = null; } - - // Let make the visible text in the node visible again ... - this._topic.getTextShape().setVisibility(true); - - // Remove it form the screen ... - this._containerElem.remove(); - this._containerElem = null; + this._topic = null; } - this._topic = null; } } - export default MultilineTextEditor;