From c37d510b9c209028f146ee8d77e1540c6fb5719c Mon Sep 17 00:00:00 2001 From: luin Date: Fri, 17 Apr 2020 11:51:52 +0800 Subject: [PATCH] Backspace at the header beginning should keep the format --- modules/keyboard.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/keyboard.js b/modules/keyboard.js index 7ebebe6cf3..bb8581f152 100644 --- a/modules/keyboard.js +++ b/modules/keyboard.js @@ -199,15 +199,19 @@ class Keyboard extends Module { // Always deleting newline here, length always 1 const [prev] = this.quill.getLine(range.index - 1); if (prev) { - const curFormats = line.formats(); - const prevFormats = this.quill.getFormat(range.index - 1, 1); - formats = AttributeMap.diff(curFormats, prevFormats) || {}; - if (Object.keys(formats).length > 0) { - // line.length() - 1 targets \n in line, another -1 for newline being deleted - const formatDelta = new Delta() - .retain(range.index + line.length() - 2) - .retain(1, formats); - delta = delta.compose(formatDelta); + const isPrevLineEmpty = + prev.statics.blotName === 'block' && prev.length() <= 1; + if (!isPrevLineEmpty) { + const curFormats = line.formats(); + const prevFormats = this.quill.getFormat(range.index - 1, 1); + formats = AttributeMap.diff(curFormats, prevFormats) || {}; + if (Object.keys(formats).length > 0) { + // line.length() - 1 targets \n in line, another -1 for newline being deleted + const formatDelta = new Delta() + .retain(range.index + line.length() - 2) + .retain(1, formats); + delta = delta.compose(formatDelta); + } } } }