From 2f6b68101629a1bb1b4c5f3018fd3accc6db5dca Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Fri, 13 Jan 2023 23:49:53 -0800 Subject: [PATCH] Add support for text copy and paste. --- packages/mindplot/src/components/Designer.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/mindplot/src/components/Designer.ts b/packages/mindplot/src/components/Designer.ts index 4e34b33b..c2f9312f 100644 --- a/packages/mindplot/src/components/Designer.ts +++ b/packages/mindplot/src/components/Designer.ts @@ -404,12 +404,21 @@ class Designer extends Events { } pasteClipboard(): void { - if (this._clipboard.length === 0) { - $notify($msg('CLIPBOARD_IS_EMPTY')); - return; + // If the no selection has been made, update with the text on the clipboard. + if (this._clipboard.length !== 0) { + this._actionDispatcher.addTopics(this._clipboard, null); + this._clipboard = []; + } else { + const topics = this.getModel().filterSelectedTopics(); + if (topics.length > 0) { + navigator.clipboard.readText().then((text) => { + this._actionDispatcher.changeTextToTopic( + topics.map((t) => t.getId()), + text.trim(), + ); + }); + } } - this._actionDispatcher.addTopics(this._clipboard, null); - this._clipboard = []; } getModel(): DesignerModel {