diff --git a/modules/keyboard.js b/modules/keyboard.js index b5c70010c0..9e3c910eb3 100644 --- a/modules/keyboard.js +++ b/modules/keyboard.js @@ -512,11 +512,7 @@ function handleDeleteRange(range) { this.quill.focus(); } -// TODO use just updateContents() function handleEnter(range, context) { - if (range.length > 0) { - this.quill.scroll.deleteAt(range.index, range.length); // So we do not trigger text-change - } const lineFormats = Object.keys(context.format).reduce((formats, format) => { if ( this.quill.scroll.query(format, Scope.BLOCK) && @@ -526,17 +522,13 @@ function handleEnter(range, context) { } return formats; }, {}); - this.quill.insertText(range.index, '\n', lineFormats, Quill.sources.USER); - // Earlier scroll.deleteAt might have messed up our selection, - // so insertText's built in selection preservation is not reliable + const delta = new Delta() + .retain(range.index) + .delete(range.length) + .insert('\n', lineFormats); + this.quill.updateContents(delta, Quill.sources.USER); this.quill.setSelection(range.index + 1, Quill.sources.SILENT); this.quill.focus(); - Object.keys(context.format).forEach(name => { - if (lineFormats[name] != null) return; - if (Array.isArray(context.format[name])) return; - if (name === 'link') return; - this.quill.format(name, context.format[name], Quill.sources.USER); - }); } function makeCodeBlockHandler(indent) {