fix bug when replacing range starting at end of previous part

This commit is contained in:
Bruno Windels 2019-08-28 15:52:39 +02:00
parent 994bcb5c85
commit c44fbb73d0
4 changed files with 66 additions and 11 deletions

View file

@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import DocumentOffset from "./offset";
export default class DocumentPosition {
constructor(index, offset) {
this._index = index;
@ -104,4 +106,18 @@ export default class DocumentPosition {
}
}
}
asOffset(model) {
if (this.index === -1) {
return new DocumentOffset(0, true);
}
let offset = 0;
for (let i = 0; i < this.index; ++i) {
offset += model.parts[i].text.length;
}
offset += this.offset;
const lastPart = model.parts[this.index];
const atEnd = offset >= lastPart.text.length;
return new DocumentOffset(offset, atEnd);
}
}