Skip to content

Commit

Permalink
check for astral symbols
Browse files Browse the repository at this point in the history
related #1230
  • Loading branch information
jhchen committed Jan 5, 2017
1 parent 4e9972d commit c55149a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions modules/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,20 @@ function handleBackspace(range, context) {
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);
// Check for astral symbols
let length = /[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(context.prefix) ? 2 : 1;
this.quill.deleteText(range.index-length, length, Quill.sources.USER);
if (Object.keys(formats).length > 0) {
this.quill.formatLine(range.index-1, 1, formats, Quill.sources.USER);
this.quill.formatLine(range.index-length, length, formats, Quill.sources.USER);
}
this.quill.selection.scrollIntoView();
}

function handleDelete(range) {
if (range.index >= this.quill.getLength() - 1) return;
this.quill.deleteText(range.index, 1, Quill.sources.USER);
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;
this.quill.deleteText(range.index, length, Quill.sources.USER);
}

function handleDeleteRange(range) {
Expand Down

0 comments on commit c55149a

Please sign in to comment.