Skip to content

Commit

Permalink
fix prepare format
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Nov 11, 2015
1 parent 498f669 commit fd32c52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/modules/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Keyboard {
this.quill.root.addEventListener('keydown', (evt) => {
let which = evt.which || evt.keyCode;
let range = undefined;
let prevent = (this.bindings[which] || []).reduce(function(prevent, binding) {
let prevent = (this.bindings[which] || []).reduce((prevent, binding) => {
let [key, callback] = binding;
if (!match(evt, key)) return prevent;
if (range === undefined) {
Expand Down
14 changes: 7 additions & 7 deletions src/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ class Selection {
if (!nativeRange.collapsed) {
positions.push([nativeRange.endContainer, nativeRange.endOffset]);
}
let indexes = positions.map(function(position) {
let indexes = positions.map((position) => {
let [container, offset] = position;
let blot = Parchment.findBlot(container, true);
return blot.findOffset(container) + offset;
return blot.offset(this.doc) + blot.findOffset(container) + offset;
});
return new Range(Math.min(...indexes), Math.max(...indexes));
}
Expand All @@ -152,15 +152,15 @@ class Selection {
let cursor, index = range.start;
let pos = this.doc.findPath(index).pop();
if (pos.blot instanceof CursorBlot) {
cursor = pos.blot;
index -= 1;
} else {
let target = pos.blot.split(pos.offset);
cursor = Parchment.create('cursor');
pos.blot.parent.insertBefore(cursor, target);
pos.blot.insertAt(pos.offset, 'cursor', {});
pos = this.doc.findPath(index + 1).pop();
// pos can be null if insertAt was a noop
if (pos == null || !(pos.blot instanceof CursorBlot)) return;
}
this.doc.formatAt(index, 1, format, value);
this.setNativeRange(cursor.textNode, 1); // Cursor will not blink if we select cursor.textNode
this.setNativeRange(pos.blot.textNode, 1); // Cursor will not blink if we select cursor.textNode
this.update();
}

Expand Down

0 comments on commit fd32c52

Please sign in to comment.