MCPcopy
hub / github.com/jsdom/jsdom / splitText

Method splitText

lib/jsdom/living/nodes/Text-impl.js:26–72  ·  view source on GitHub ↗
(offset)

Source from the content-addressed store, hash-verified

24 // https://dom.spec.whatwg.org/#dom-text-splittext
25 // https://dom.spec.whatwg.org/#concept-text-split
26 splitText(offset) {
27 const { length } = this;
28
29 if (offset > length) {
30 throw DOMException.create(this._globalObject, ["The index is not in the allowed range.", "IndexSizeError"]);
31 }
32
33 const count = length - offset;
34 const newData = this.substringData(offset, count);
35
36 const newNode = this._ownerDocument.createTextNode(newData);
37
38 const parent = domSymbolTree.parent(this);
39
40 if (parent !== null) {
41 parent._insert(newNode, this.nextSibling);
42
43 for (const range of this._liveRanges()) {
44 const { _start, _end } = range;
45
46 if (_start.node === this && _start.offset > offset) {
47 range._setLiveRangeStart(newNode, _start.offset - offset);
48 }
49
50 if (_end.node === this && _end.offset > offset) {
51 range._setLiveRangeEnd(newNode, _end.offset - offset);
52 }
53 }
54
55 const nodeIndex = domSymbolTree.index(this);
56 for (const range of parent._liveRanges()) {
57 const { _start, _end } = range;
58
59 if (_start.node === parent && _start.offset === nodeIndex + 1) {
60 range._setLiveRangeStart(parent, _start.offset + 1);
61 }
62
63 if (_end.node === parent && _end.offset === nodeIndex + 1) {
64 range._setLiveRangeEnd(parent, _end.offset + 1);
65 }
66 }
67 }
68
69 this.replaceData(offset, count, "");
70
71 return newNode;
72 }
73
74 // https://dom.spec.whatwg.org/#dom-text-wholetext
75 get wholeText() {

Callers 3

insertNodeInRangeFunction · 0.80
core.jsFile · 0.80
html.jsFile · 0.80

Calls 8

substringDataMethod · 0.80
createTextNodeMethod · 0.80
_liveRangesMethod · 0.80
_setLiveRangeStartMethod · 0.80
_setLiveRangeEndMethod · 0.80
indexMethod · 0.80
replaceDataMethod · 0.80
_insertMethod · 0.45

Tested by

no test coverage detected