Skip to content

Commit

Permalink
handle delete at end of list, fixes #1277
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Apr 17, 2017
1 parent d1f3737 commit b3494f8
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions modules/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,13 @@ function handleBackspace(range, context) {
if (range.index === 0 || this.quill.getLength() <= 1) return;
let [line, ] = this.quill.getLine(range.index);
let formats = {};
if (context.offset === 0 && line.prev != null && line.prev.length() > 1) {
let curFormats = line.formats();
let prevFormats = this.quill.getFormat(range.index-1, 1);
formats = DeltaOp.attributes.diff(curFormats, prevFormats) || {};
if (context.offset === 0) {
let [prev, ] = this.quill.getLine(range.index - 1);
if (prev != null && prev.length() > 1) {
let curFormats = line.formats();
let prevFormats = this.quill.getFormat(range.index-1, 1);
formats = DeltaOp.attributes.diff(curFormats, prevFormats) || {};
}
}
// Check for astral symbols
let length = /[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(context.prefix) ? 2 : 1;
Expand All @@ -297,7 +300,21 @@ function handleDelete(range, context) {
// Check for astral symbols
let length = /^[\uD800-\uDBFF][\uDC00-\uDFFF]/.test(context.suffix) ? 2 : 1;
if (range.index >= this.quill.getLength() - length) return;
let formats = {}, nextLength = 0;
let [line, ] = this.quill.getLine(range.index);
if (context.offset >= line.length() - 1) {
let [next, ] = this.quill.getLine(range.index + 1);
if (next) {
let curFormats = line.formats();
let nextFormats = this.quill.getFormat(range.index, 1);
formats = DeltaOp.attributes.diff(curFormats, nextFormats) || {};
nextLength = next.length();
}
}
this.quill.deleteText(range.index, length, Quill.sources.USER);
if (Object.keys(formats).length > 0) {
this.quill.formatLine(range.index + nextLength - 1, length, formats, Quill.sources.USER);
}
}

function handleDeleteRange(range) {
Expand Down

0 comments on commit b3494f8

Please sign in to comment.