@yorkie-js/sdk 0.6.43 → 0.6.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6302,9 +6302,10 @@
6302
6302
  return this.root ? this.root.getWeight() : 0;
6303
6303
  }
6304
6304
  /**
6305
- * `find` returns the Node and offset of the given index.
6305
+ * `findForText` returns the Node and offset of the given position (cursor).
6306
+ * Used for Text where cursor placed between characters.
6306
6307
  */
6307
- find(pos) {
6308
+ findForText(pos) {
6308
6309
  if (!this.root || pos < 0) {
6309
6310
  return [void 0, 0];
6310
6311
  }
@@ -6329,6 +6330,34 @@
6329
6330
  this.splayNode(node);
6330
6331
  return [node, pos];
6331
6332
  }
6333
+ /**
6334
+ * `findForArray` returns the Node of the given position (index).
6335
+ * Used for Array where index points to the element.
6336
+ */
6337
+ findForArray(idx) {
6338
+ if (!this.root) {
6339
+ return void 0;
6340
+ }
6341
+ if (idx < 0 || idx >= this.length) {
6342
+ throw new YorkieError(
6343
+ Code.ErrInvalidArgument,
6344
+ `out of index range: idx: ${idx}, length: ${this.length}`
6345
+ );
6346
+ }
6347
+ let node = this.root;
6348
+ for (; ; ) {
6349
+ if (node.hasLeft() && idx < node.getLeftWeight()) {
6350
+ node = node.getLeft();
6351
+ } else if (node.hasRight() && node.getLeftWeight() + node.getLength() <= idx) {
6352
+ idx -= node.getLeftWeight() + node.getLength();
6353
+ node = node.getRight();
6354
+ } else {
6355
+ break;
6356
+ }
6357
+ }
6358
+ this.splayNode(node);
6359
+ return node;
6360
+ }
6332
6361
  /**
6333
6362
  * Find the index of the given node in BST.
6334
6363
  *
@@ -8011,15 +8040,8 @@
8011
8040
  if (idx >= this.length) {
8012
8041
  return;
8013
8042
  }
8014
- const [node, offset] = this.nodeMapByIndex.find(idx);
8015
- let rgaNode = node;
8016
- if (idx === 0 && node === this.dummyHead || offset > 0) {
8017
- do {
8018
- if (rgaNode) {
8019
- rgaNode = rgaNode.getNext();
8020
- }
8021
- } while (rgaNode && rgaNode.isRemoved());
8022
- }
8043
+ const node = this.nodeMapByIndex.findForArray(idx);
8044
+ const rgaNode = node;
8023
8045
  return rgaNode;
8024
8046
  }
8025
8047
  /**
@@ -9486,7 +9508,7 @@
9486
9508
  * `indexToPos` finds RGATreeSplitPos of given offset.
9487
9509
  */
9488
9510
  indexToPos(idx) {
9489
- const [node, offset] = this.treeByIndex.find(idx);
9511
+ const [node, offset] = this.treeByIndex.findForText(idx);
9490
9512
  const splitNode = node;
9491
9513
  return RGATreeSplitPos.of(splitNode.getID(), offset);
9492
9514
  }
@@ -19251,7 +19273,7 @@
19251
19273
  };
19252
19274
  }
19253
19275
  const name = "@yorkie-js/sdk";
19254
- const version = "0.6.43";
19276
+ const version = "0.6.44";
19255
19277
  const pkg = {
19256
19278
  name,
19257
19279
  version