From 9ef90a70572d35940967c88e1b7e158931f965de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Thu, 22 Aug 2024 18:43:02 +0800 Subject: [PATCH] =?UTF-8?q?Quill=E5=8D=87=E7=BA=A7=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dshift+enter=E6=8D=A2=E8=A1=8C=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E6=96=B0=E8=A1=8C=E6=B2=A1=E6=9C=89=E6=A0=B7=E5=BC=8F=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/plugins/RichText.js | 39 ++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/simple-mind-map/src/plugins/RichText.js b/simple-mind-map/src/plugins/RichText.js index 5dd1ee52..2388c33f 100644 --- a/simple-mind-map/src/plugins/RichText.js +++ b/simple-mind-map/src/plugins/RichText.js @@ -14,6 +14,7 @@ import { } from '../utils' import { CONSTANTS } from '../constants/constant' import MindMapNode from '../core/render/node/MindMapNode' +import { Scope } from 'parchment' let extended = false @@ -377,7 +378,43 @@ class RichText { enter: { key: 'Enter', handler: function () { - // 覆盖默认的回车键换行 + // 覆盖默认的回车键,禁止换行 + } + }, + shiftEnter: { + key: 'Enter', + shiftKey: true, + handler: function (range, context) { + // 覆盖默认的换行,默认情况下新行的样式会丢失 + const lineFormats = Object.keys(context.format).reduce( + (formats, format) => { + if ( + this.quill.scroll.query(format, Scope.BLOCK) && + !Array.isArray(context.format[format]) + ) { + formats[format] = context.format[format] + } + return formats + }, + {} + ) + const delta = new Delta() + .retain(range.index) + .delete(range.length) + .insert('\n', lineFormats) + this.quill.updateContents(delta, Quill.sources.USER) + this.quill.setSelection(range.index + 1, Quill.sources.SILENT) + this.quill.focus() + Object.keys(context.format).forEach(name => { + if (lineFormats[name] != null) return + if (Array.isArray(context.format[name])) return + if (name === 'code' || name === 'link') return + this.quill.format( + name, + context.format[name], + Quill.sources.USER + ) + }) } }, tab: {