From c55149a0919cf71782a0fff8ce5e22ab38402cfe Mon Sep 17 00:00:00 2001 From: Jason Chen Date: Thu, 5 Jan 2017 14:23:34 -0800 Subject: [PATCH] check for astral symbols related #1230 --- modules/keyboard.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/keyboard.js b/modules/keyboard.js index 416771cca7..a27a53d05e 100644 --- a/modules/keyboard.js +++ b/modules/keyboard.js @@ -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) {