Skip to content

Commit

Permalink
fix slab#703
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed May 30, 2016
1 parent 036110e commit 9b25350
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion blots/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@ class Cursor extends Embed {
}
this.remove();
if (range != null && range.start.node === textNode && range.end.node === textNode) {
this.selection.setNativeRange(textNode, Math.max(0, range.start.offset - 1), textNode, Math.max(0, range.end.offset - 1));
// optimize() might move the cursor after our restore
let [start, end] = [range.start.offset, range.end.offset].map(function(offset) {
return Math.max(0, Math.min(textNode.data.length, offset - 1));
});
setTimeout(() => {
// optimize() might move selection after us
this.selection.setNativeRange(textNode, start, textNode, end);
}, 1);
}
}

Expand Down
1 change: 1 addition & 0 deletions core/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Selection {
this.emitter.on(Emitter.events.SCROLL_BEFORE_UPDATE, () => {
let native = this.getNativeRange();
if (native == null) return;
if (native.start.node === this.cursor.textNode) return; // cursor.restore() will handle
// TODO unclear if this has negative side effects
this.emitter.once(Emitter.events.SCROLL_UPDATE, () => {
try {
Expand Down

0 comments on commit 9b25350

Please sign in to comment.