From 3595f14da7fc7ebef4588272b9039968982d3d87 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Sat, 2 Dec 2017 01:45:22 -0800 Subject: [PATCH] fix insert in y-text --- src/Type/YText.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Type/YText.js b/src/Type/YText.js index 22a1afbe..16dd9318 100644 --- a/src/Type/YText.js +++ b/src/Type/YText.js @@ -29,14 +29,17 @@ export default class YText extends YArray { let right = this._start let count = 0 while (right !== null) { - if (count <= pos && pos < count + right._length) { + const rightLen = right._deleted ? 0 : (right._length - 1) + if (count <= pos && pos <= count + rightLen) { const splitDiff = pos - count - right = right._splitAt(this._y, pos - count) + right = right._splitAt(this._y, splitDiff) left = right._left count += splitDiff break } - count += right._length + if (!right._deleted) { + count += right._length + } left = right right = right._right }