From 037ac29c578257c7a86b0c766bda9f8c3cef7f4b Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 4 Sep 2019 16:02:07 +0200 Subject: [PATCH] be more forgiving with offset that don't have atNodeEnd=true if index is not found, it means the last position should be returned if there is any. We still return -1 for empty documents, as index should always point to a valid part if positive. --- src/editor/model.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/editor/model.js b/src/editor/model.js index a121c67b48..3b4f1ce460 100644 --- a/src/editor/model.js +++ b/src/editor/model.js @@ -388,7 +388,11 @@ export default class EditorModel { currentOffset += partLen; return false; }); - return new DocumentPosition(index, totalOffset - currentOffset); + if (index === -1) { + return this.getPositionAtEnd(); + } else { + return new DocumentPosition(index, totalOffset - currentOffset); + } } /**