Skip to content

Commit

Permalink
Backspace at the header beginning should keep the format (#3013)
Browse files Browse the repository at this point in the history
  • Loading branch information
luin authored Apr 20, 2020
1 parent ecf7720 commit 676816a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions modules/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down

0 comments on commit 676816a

Please sign in to comment.