From 904043cb326a930548bc76a26f8a4694d99dce94 Mon Sep 17 00:00:00 2001 From: Jason Chen Date: Wed, 7 Sep 2016 14:35:57 -0700 Subject: [PATCH] fix #928 --- modules/keyboard.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/keyboard.js b/modules/keyboard.js index 2857b6c025..601c3f656c 100644 --- a/modules/keyboard.js +++ b/modules/keyboard.js @@ -2,6 +2,7 @@ import clone from 'clone'; import equal from 'deep-equal'; import extend from 'extend'; import Delta from 'rich-text/lib/delta'; +import DeltaOp from 'rich-text/lib/op'; import Parchment from 'parchment'; import Quill from '../core/quill'; import logger from '../core/logger'; @@ -37,9 +38,17 @@ class Keyboard extends Module { this.addBinding({ key: Keyboard.keys.ENTER, metaKey: null, ctrlKey: null, altKey: null }, function() {}); this.addBinding({ key: Keyboard.keys.BACKSPACE }, { collapsed: true, prefix: /^.?$/ }, function(range, context) { if (range.index === 0) return; - let index = context.offset === 0 ? range.index : range.index - 1; - this.quill.deleteText(index, 1, Quill.sources.USER); - this.quill.setSelection(range.index-1, Quill.sources.SILENT); + let [line, ] = this.quill.scroll.line(range.index); + let formats = {}; + if (context.offset === 0) { + let curFormats = line.formats(); + let prevFormats = this.quill.getFormat(range.index-1, 1); + formats = DeltaOp.attributes.diff(curFormats, prevFormats) || {}; + } + this.quill.deleteText(range.index-1, 1, Quill.sources.USER); + if (Object.keys(formats).length > 0) { + this.quill.formatLine(range.index-1, 1, formats, Quill.sources.USER); + } this.quill.selection.scrollIntoView(); }); this.addBinding({ key: Keyboard.keys.DELETE }, { collapsed: true, suffix: /^$/ }, function(range) {