Skip to content

Commit

Permalink
dont preserve inline formatting on enter
Browse files Browse the repository at this point in the history
rarely what people want from UX perspective
  • Loading branch information
jhchen committed Apr 16, 2019
1 parent 19848d1 commit 70e76a5
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions modules/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand All @@ -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) {
Expand Down

0 comments on commit 70e76a5

Please sign in to comment.