From 7e433852f57d6456b5074341b0a38af0dc37204e Mon Sep 17 00:00:00 2001 From: js87zz Date: Mon, 20 Dec 2021 15:36:54 +0900 Subject: [PATCH] fix: fill the link popup text field with the selected text --- apps/editor/src/editorCore.ts | 2 ++ apps/editor/src/markdown/mdPreview.ts | 2 +- apps/editor/src/ui/components/toolbar/toolbarButton.ts | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/editor/src/editorCore.ts b/apps/editor/src/editorCore.ts index 84d86ef812..6f16285201 100644 --- a/apps/editor/src/editorCore.ts +++ b/apps/editor/src/editorCore.ts @@ -42,6 +42,7 @@ import { cls, replaceBRWithEmptyBlock } from './utils/dom'; import { sanitizeHTML } from './sanitizer/htmlSanitizer'; import { createHTMLSchemaMap } from './wysiwyg/nodes/html'; import { getHTMLRenderConvertors } from './markdown/htmlRenderConvertors'; +import { buildQuery } from './queries/queryManager'; /** * ToastUIEditorCore @@ -273,6 +274,7 @@ class ToastUIEditorCore { this.scrollSync = new ScrollSync(this.mdEditor, this.preview, this.eventEmitter); this.addInitEvent(); this.addInitCommand(mdCommands, wwCommands); + buildQuery(this); if (this.options.hooks) { forEachOwnProperties(this.options.hooks, (fn, key) => this.addHook(key, fn)); diff --git a/apps/editor/src/markdown/mdPreview.ts b/apps/editor/src/markdown/mdPreview.ts index d254d4bc78..ebff3edad0 100644 --- a/apps/editor/src/markdown/mdPreview.ts +++ b/apps/editor/src/markdown/mdPreview.ts @@ -220,7 +220,7 @@ class MarkdownPreview { } getElement() { - return this.el; + return this.el!; } getHTML() { diff --git a/apps/editor/src/ui/components/toolbar/toolbarButton.ts b/apps/editor/src/ui/components/toolbar/toolbarButton.ts index fda07e0efc..415ed467a3 100644 --- a/apps/editor/src/ui/components/toolbar/toolbarButton.ts +++ b/apps/editor/src/ui/components/toolbar/toolbarButton.ts @@ -54,17 +54,20 @@ export class ToolbarButtonComp extends Component { }; private execCommand = () => { - const { item, execCommand, setPopupInfo, getBound } = this.props; + const { item, execCommand, setPopupInfo, getBound, eventEmitter } = this.props; const { command, name, popup } = item; if (command) { execCommand(command); } else { const popupName = popup ? 'customPopupBody' : name; + const [initialValues] = eventEmitter.emit('query', 'getPopupInitialValues', { popupName }); + const info = createPopupInfo(popupName, { el: this.refs.el, pos: getBound(this.refs.el), popup, + initialValues, }); if (info) {