From ac6a258da853f44ab0e236090dc73c25bbc5c44f Mon Sep 17 00:00:00 2001 From: yanmao <55792257+yanmao-cc@users.noreply.github.com> Date: Wed, 29 Dec 2021 23:34:19 +0800 Subject: [PATCH] fix(codeblock): unable to save the selected language --- packages/engine/src/engine/index.ts | 2 +- packages/engine/src/types/engine.ts | 11 ++++++----- packages/engine/src/view.ts | 2 +- plugins/codeblock-vue/src/component/editor.ts | 2 +- plugins/codeblock-vue/src/component/index.ts | 2 +- plugins/codeblock/src/component/editor.ts | 2 +- plugins/codeblock/src/component/index.ts | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/engine/src/engine/index.ts b/packages/engine/src/engine/index.ts index 5db28b0d..591c0edb 100644 --- a/packages/engine/src/engine/index.ts +++ b/packages/engine/src/engine/index.ts @@ -113,7 +113,7 @@ class Engine implements EngineInterface { // 查找父级样式 overflow 或者 overflow-y 为 auto 或者 scroll 的节点 const targetValues = ['auto', 'scroll']; let parent = this.container.parent(); - while (parent && parent.length > 0 && parent.name !== 'body') { + while (!sn && parent && parent.length > 0 && parent.name !== 'body') { if ( targetValues.includes(parent.css('overflow')) || targetValues.includes(parent.css('overflow-y')) diff --git a/packages/engine/src/types/engine.ts b/packages/engine/src/types/engine.ts index e4515cb0..af3c1b00 100644 --- a/packages/engine/src/types/engine.ts +++ b/packages/engine/src/types/engine.ts @@ -137,6 +137,12 @@ export interface EditorInterface { * 剪切板 */ clipboard: ClipboardInterface; + + /** + * 设置滚动节点 + * @param node 节点 + */ + setScrollNode(node: HTMLElement): void; /** * 绑定事件 * @param eventType 事件类型 @@ -532,11 +538,6 @@ export interface EngineInterface extends EditorInterface { * 是否为空内容 */ isEmpty(): boolean; - /** - * 设置滚动节点 - * @param node 节点 - */ - setScrollNode(node: HTMLElement): void; /** * 获取编辑器值 * @param ignoreCursor 是否包含光标位置信息 diff --git a/packages/engine/src/view.ts b/packages/engine/src/view.ts index 40bf9790..bbec1c1f 100644 --- a/packages/engine/src/view.ts +++ b/packages/engine/src/view.ts @@ -115,7 +115,7 @@ class View implements ViewInterface { // 查找父级样式 overflow 或者 overflow-y 为 auto 或者 scroll 的节点 const targetValues = ['auto', 'scroll']; let parent = this.container.parent(); - while (parent && parent.length > 0 && parent.name !== 'body') { + while (!sn && parent && parent.length > 0 && parent.name !== 'body') { if ( targetValues.includes(parent.css('overflow')) || targetValues.includes(parent.css('overflow-y')) diff --git a/plugins/codeblock-vue/src/component/editor.ts b/plugins/codeblock-vue/src/component/editor.ts index 43049bdc..47bd002e 100644 --- a/plugins/codeblock-vue/src/component/editor.ts +++ b/plugins/codeblock-vue/src/component/editor.ts @@ -155,7 +155,7 @@ class CodeBlockEditor implements CodeBlockEditorInterface { 'readOnly', !isEngine(this.editor) || this.editor.readonly ? true : false, ); - if (code !== undefined) this.save(); + this.save(); } render(mode: string, value: string, options?: EditorConfiguration) { diff --git a/plugins/codeblock-vue/src/component/index.ts b/plugins/codeblock-vue/src/component/index.ts index 384d13bf..78cccfaa 100644 --- a/plugins/codeblock-vue/src/component/index.ts +++ b/plugins/codeblock-vue/src/component/index.ts @@ -174,7 +174,7 @@ class CodeBlcok extends Card { if (!this.codeEditor.container.inEditor()) { this.codeEditor.container = $(this.codeEditor.renderTemplate()); this.mirror = undefined; - this.getCenter().append(this.codeEditor.container); + this.getCenter().empty().append(this.codeEditor.container); } const value = this.getValue(); diff --git a/plugins/codeblock/src/component/editor.ts b/plugins/codeblock/src/component/editor.ts index 0b04baab..e3d41548 100644 --- a/plugins/codeblock/src/component/editor.ts +++ b/plugins/codeblock/src/component/editor.ts @@ -156,7 +156,7 @@ class CodeBlockEditor implements CodeBlockEditorInterface { 'readOnly', !isEngine(this.editor) || this.editor.readonly ? true : false, ); - if (code !== undefined) this.save(); + this.save(); } render(mode: string, value: string, options?: EditorConfiguration) { diff --git a/plugins/codeblock/src/component/index.ts b/plugins/codeblock/src/component/index.ts index cfc50a88..a222dfee 100644 --- a/plugins/codeblock/src/component/index.ts +++ b/plugins/codeblock/src/component/index.ts @@ -171,7 +171,7 @@ class CodeBlcok extends Card { if (!this.codeEditor.container.inEditor()) { this.codeEditor.container = $(this.codeEditor.renderTemplate()); this.mirror = undefined; - this.getCenter().append(this.codeEditor.container); + this.getCenter().empty().append(this.codeEditor.container); } const value = this.getValue();