Skip to content

Commit

Permalink
fix exiting from code block
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Apr 11, 2018
1 parent d9f4c57 commit b9c5e87
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions modules/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,31 @@ Keyboard.DEFAULTS = {
key: 'Enter',
collapsed: true,
format: ['code-block'],
prefix: /\n\n$/,
suffix: /^[ \t\v]*\n$/,
prefix: /^$/,
suffix: /^\s*$/,
handler(range) {
const [line, offset] = this.quill.getLine(range.index);
const delta = new Delta()
.retain(range.index + line.length() - offset - 2)
.retain(1, { 'code-block': null })
.delete(1);
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(range.index - 1, Quill.sources.SILENT);
let numLines = 2;
let cur = line;
while (
cur != null &&
cur.length() <= 1 &&
cur.formats()['code-block']
) {
cur = cur.prev;
numLines -= 1;
// Requisite prev lines are empty
if (numLines <= 0) {
const delta = new Delta()
.retain(range.index + line.length() - offset - 2)
.retain(1, { 'code-block': null })
.delete(1);
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(range.index - 1, Quill.sources.SILENT);
return false;
}
}
return true;
},
},
'embed left': makeEmbedArrowHandler('ArrowLeft', false),
Expand Down

0 comments on commit b9c5e87

Please sign in to comment.