( screen: Screen, x: number, y: number, cell: Cell, )
| 691 | * automatically - it will be set directly by the wrapping code. |
| 692 | */ |
| 693 | export function setCellAt( |
| 694 | screen: Screen, |
| 695 | x: number, |
| 696 | y: number, |
| 697 | cell: Cell, |
| 698 | ): void { |
| 699 | if (x < 0 || y < 0 || x >= screen.width || y >= screen.height) return |
| 700 | const ci = (y * screen.width + x) << 1 |
| 701 | const cells = screen.cells |
| 702 | |
| 703 | // When a Wide char is overwritten by a Narrow char, its SpacerTail remains |
| 704 | // as a ghost cell that the diff/render pipeline skips, causing stale content |
| 705 | // to leak through from previous frames. |
| 706 | const prevWidth = cells[ci + 1]! & WIDTH_MASK |
| 707 | if (prevWidth === CellWidth.Wide && cell.width !== CellWidth.Wide) { |
| 708 | const spacerX = x + 1 |
| 709 | if (spacerX < screen.width) { |
| 710 | const spacerCI = ci + 2 |
| 711 | if ((cells[spacerCI + 1]! & WIDTH_MASK) === CellWidth.SpacerTail) { |
| 712 | cells[spacerCI] = EMPTY_CHAR_INDEX |
| 713 | cells[spacerCI + 1] = packWord1( |
| 714 | screen.emptyStyleId, |
| 715 | 0, |
| 716 | CellWidth.Narrow, |
| 717 | ) |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | // Track cleared Wide position for damage expansion below |
| 722 | let clearedWideX = -1 |
| 723 | if ( |
| 724 | prevWidth === CellWidth.SpacerTail && |
| 725 | cell.width !== CellWidth.SpacerTail |
| 726 | ) { |
| 727 | // Overwriting a SpacerTail: clear the orphaned Wide char at (x-1). |
| 728 | // Keeping the wide character with Narrow width would cause the terminal |
| 729 | // to still render it with width 2, desyncing the cursor model. |
| 730 | if (x > 0) { |
| 731 | const wideCI = ci - 2 |
| 732 | if ((cells[wideCI + 1]! & WIDTH_MASK) === CellWidth.Wide) { |
| 733 | cells[wideCI] = EMPTY_CHAR_INDEX |
| 734 | cells[wideCI + 1] = packWord1(screen.emptyStyleId, 0, CellWidth.Narrow) |
| 735 | clearedWideX = x - 1 |
| 736 | } |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | // Pack cell data into cells array |
| 741 | cells[ci] = internCharString(screen, cell.char) |
| 742 | cells[ci + 1] = packWord1( |
| 743 | cell.styleId, |
| 744 | internHyperlink(screen, cell.hyperlink), |
| 745 | cell.width, |
| 746 | ) |
| 747 | |
| 748 | // Track damage - expand bounds in place instead of allocating new objects |
| 749 | // Include the main cell position and any cleared orphan cells |
| 750 | const minX = clearedWideX >= 0 ? Math.min(x, clearedWideX) : x |
no test coverage detected