Skip to content

Commit

Permalink
fix #928
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Sep 7, 2016
1 parent bc87534 commit 904043c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions modules/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down

1 comment on commit 904043c

@scottmessinger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks so much!

Please sign in to comment.