From e491665df889635269299c41cede41de3c6c88cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Mon, 24 Jun 2019 11:56:53 +0200 Subject: [PATCH] check if focus position is in document range --- packages/tiptap/src/Editor.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/tiptap/src/Editor.js b/packages/tiptap/src/Editor.js index 46f94c35..a8696ee6 100644 --- a/packages/tiptap/src/Editor.js +++ b/packages/tiptap/src/Editor.js @@ -355,6 +355,10 @@ export default class Editor extends Emitter { pos = this.state.doc.nodeSize - 2 } + // selection should be inside of the document range + pos = Math.max(0, pos) + pos = Math.min(this.state.doc.nodeSize - 2, pos) + const selection = TextSelection.near(this.state.doc.resolve(pos)) const transaction = this.state.tr.setSelection(selection) this.view.dispatch(transaction)