| 610 | } |
| 611 | |
| 612 | [kNormalWrite](b) { |
| 613 | if (b === undefined) { |
| 614 | return; |
| 615 | } |
| 616 | let string = this[kDecoder].write(b); |
| 617 | if ( |
| 618 | this[kSawReturnAt] && |
| 619 | DateNow() - this[kSawReturnAt] <= this.crlfDelay |
| 620 | ) { |
| 621 | if (StringPrototypeCodePointAt(string) === 10) string = StringPrototypeSlice(string, 1); |
| 622 | this[kSawReturnAt] = 0; |
| 623 | } |
| 624 | |
| 625 | // Run test() on the new string chunk, not on the entire line buffer. |
| 626 | let newPartContainsEnding = RegExpPrototypeExec(lineEnding, string); |
| 627 | if (newPartContainsEnding !== null) { |
| 628 | if (this[kLine_buffer]) { |
| 629 | string = this[kLine_buffer] + string; |
| 630 | this[kLine_buffer] = null; |
| 631 | lineEnding.lastIndex = 0; // Start the search from the beginning of the string. |
| 632 | newPartContainsEnding = RegExpPrototypeExec(lineEnding, string); |
| 633 | } |
| 634 | this[kSawReturnAt] = StringPrototypeEndsWith(string, '\r') ? |
| 635 | DateNow() : |
| 636 | 0; |
| 637 | |
| 638 | const indexes = [0, newPartContainsEnding.index, lineEnding.lastIndex]; |
| 639 | let nextMatch; |
| 640 | while ((nextMatch = RegExpPrototypeExec(lineEnding, string)) !== null) { |
| 641 | ArrayPrototypePush(indexes, nextMatch.index, lineEnding.lastIndex); |
| 642 | } |
| 643 | const lastIndex = indexes.length - 1; |
| 644 | // Either '' or (conceivably) the unfinished portion of the next line |
| 645 | this[kLine_buffer] = StringPrototypeSlice(string, indexes[lastIndex]); |
| 646 | for (let i = 1; i < lastIndex; i += 2) { |
| 647 | this[kOnLine](StringPrototypeSlice(string, indexes[i - 1], indexes[i])); |
| 648 | } |
| 649 | } else if (string) { |
| 650 | // No newlines this time, save what we have for next time |
| 651 | if (this[kLine_buffer]) { |
| 652 | this[kLine_buffer] += string; |
| 653 | } else { |
| 654 | this[kLine_buffer] = string; |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | [kInsertString](c) { |
| 660 | this[kBeforeEdit](this.line, this.cursor); |