* Removes the characters from `start` to `end` (of the original string, **not** the generated string). * Content appended or prepended at positions strictly inside the range is removed with it, while * content attached at `start` or `end` is preserved — use `s.overwrite(start, end, '')` to rem
(start: number, end: number)
| 897 | * Repeated removals and removals with partially overlapping ranges are allowed. |
| 898 | */ |
| 899 | remove(start: number, end: number): this { |
| 900 | start = this._resolveIndex(start) |
| 901 | end = this._resolveIndex(end) |
| 902 | |
| 903 | if (start === end) |
| 904 | return this |
| 905 | |
| 906 | if (start < 0 || end > this.original.length) { |
| 907 | throw new MagicStringError(`range ${start}–${end} is out of bounds`) |
| 908 | } |
| 909 | if (start > end) { |
| 910 | throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`) |
| 911 | } |
| 912 | |
| 913 | this._split(start) |
| 914 | this._split(end) |
| 915 | |
| 916 | let chunk = this.byStart.get(start) |
| 917 | |
| 918 | while (chunk) { |
| 919 | // inserts anchored to the edges of the removed range are kept; only |
| 920 | // inserts strictly inside the range are removed with the original chars |
| 921 | if (chunk.start > start) |
| 922 | chunk.intro = '' |
| 923 | if (chunk.end < end) |
| 924 | chunk.outro = '' |
| 925 | chunk.edit('', false, true) |
| 926 | chunk.replacesUntil = -1 |
| 927 | chunk.replacedFrom = -1 |
| 928 | |
| 929 | chunk = end > chunk.end ? this.byStart.get(chunk.end) : undefined |
| 930 | } |
| 931 | |
| 932 | return this |
| 933 | } |
| 934 | |
| 935 | /** |
| 936 | * Reset the modified characters from `start` to `end` (of the original string, **not** the generated string). |
no test coverage detected