From f6a44609f9ddb69cc4633293d16e34522ac2c11a Mon Sep 17 00:00:00 2001 From: Donald Shen Date: Wed, 4 Mar 2020 17:14:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BE=93=E5=85=A5=E6=B3=95=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E9=97=AE=E9=A2=98=20(#81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 输入法相关问题 * docs: 补充注释 --- src/defaultEditorOptions.js | 4 +++- src/plugin/FixComposing.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/plugin/FixComposing.js diff --git a/src/defaultEditorOptions.js b/src/defaultEditorOptions.js index e7c4ed6..7d40bad 100644 --- a/src/defaultEditorOptions.js +++ b/src/defaultEditorOptions.js @@ -34,6 +34,7 @@ import FullScreen from './plugin/FullScreen' import ExtraFormat from './plugin/ExtraFormat' import RemoveFormat from './plugin/RemoveFormat/RemoveFormat' import AttachmentUpload from './plugin/AttachmentUpload' +import FixComposing from './plugin/FixComposing' export default { plugins: [ @@ -67,7 +68,8 @@ export default { FullScreen, ExtraFormat, RemoveFormat, - AttachmentUpload + AttachmentUpload, + FixComposing ], toolbar: [ 'undo', diff --git a/src/plugin/FixComposing.js b/src/plugin/FixComposing.js new file mode 100644 index 0000000..d9c56ea --- /dev/null +++ b/src/plugin/FixComposing.js @@ -0,0 +1,30 @@ +/** + * @hack 如果哪天崩了要看回 @ckeditor/ckeditor5-engine/src/view/{view|renderer}.js 源码 + * 已知负面影响:在线协作功能 + * + * 详情看相关 issues & pr: + * - https://github.com/ckeditor/ckeditor5/issues/5877 + * - https://github.com/ckeditor/ckeditor5-engine/pull/861 + * + * PS:这个可能是更优的方案,如果还有问题的话可以参考 + * https://github.com/ckeditor/ckeditor5/issues/5877#issuecomment-566369164 + * https://github.com/mycolorway/ckeditor5-engine/commit/7d921207054e327088fe7496a8cde451ddd87423 + */ +export default function(editor) { + const {_renderer, document} = editor.editing.view + /** + * 注入 isComposing,在 render 中使用 + * @see https://github.com/ckeditor/ckeditor5-engine/pull/861/files#diff-644366cecbdf61171130f59482de38e0R114 + */ + _renderer.bind('isComposing').to(document) + const {render} = _renderer + /** + * 输入法进行间停止 render + * https://github.com/ckeditor/ckeditor5-engine/pull/861/files#diff-4c87133ed830fc4ea0646426deba32cfR188 + */ + _renderer.render = function() { + // console.log('isComposing', this.isComposing) + if (this.isComposing) return + return render.call(this) + } +}