From 676816a57752cb1fdcefa7b335bc2a035d261e02 Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Tue, 21 Apr 2020 07:13:33 +0800 Subject: [PATCH] Backspace at the header beginning should keep the format (#3013) --- 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); + } } } }