MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / move

Method move

benchmark/data.js:478–504  ·  view source on GitHub ↗
(start, end, index)

Source from the content-addressed store, hash-verified

476 return this.prependRight(index, content);
477 }
478 move(start, end, index) {
479 if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
480 this._split(start);
481 this._split(end);
482 this._split(index);
483 const first = this.byStart[start];
484 const last = this.byEnd[end];
485 const oldLeft = first.previous;
486 const oldRight = last.next;
487 const newRight = this.byStart[index];
488 if (!newRight && last === this.lastChunk) return this;
489 const newLeft = newRight ? newRight.previous : this.lastChunk;
490 if (oldLeft) oldLeft.next = oldRight;
491 if (oldRight) oldRight.previous = oldLeft;
492 if (newLeft) newLeft.next = first;
493 if (newRight) newRight.previous = last;
494 if (!first.previous) this.firstChunk = last.next;
495 if (!last.next) {
496 this.lastChunk = first.previous;
497 this.lastChunk.next = null;
498 }
499 first.previous = newLeft;
500 last.next = newRight || null;
501 if (!newLeft) this.firstChunk = first;
502 if (!newRight) this.lastChunk = last;
503 return this;
504 }
505 overwrite(start, end, content, options) {
506 if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
507 while (start < 0) start += this.original.length;

Callers

nothing calls this directly

Calls 1

_splitMethod · 0.95

Tested by

no test coverage detected