MCPcopy Create free account
hub / github.com/Noumena-Network/code / setCellAt

Function setCellAt

src/ink/screen.ts:920–1041  ·  view source on GitHub ↗
(
  screen: Screen,
  x: number,
  y: number,
  cell: Cell,
)

Source from the content-addressed store, hash-verified

918 * automatically - it will be set directly by the wrapping code.
919 */
920export function setCellAt(
921 screen: Screen,
922 x: number,
923 y: number,
924 cell: Cell,
925): void {
926 if (x < 0 || y < 0 || x >= screen.width || y >= screen.height) return
927 const ci = (y * screen.width + x) << 1
928 const cells = screen.cells
929
930 // When a Wide char is overwritten by a Narrow char, its SpacerTail remains
931 // as a ghost cell that the diff/render pipeline skips, causing stale content
932 // to leak through from previous frames.
933 const prevWidth = cells[ci + 1]! & WIDTH_MASK
934 if (prevWidth === CellWidth.Wide && cell.width !== CellWidth.Wide) {
935 const spacerX = x + 1
936 if (spacerX < screen.width) {
937 const spacerCI = ci + 2
938 if ((cells[spacerCI + 1]! & WIDTH_MASK) === CellWidth.SpacerTail) {
939 cells[spacerCI] = EMPTY_CHAR_INDEX
940 cells[spacerCI + 1] = packWord1(
941 screen.emptyStyleId,
942 0,
943 CellWidth.Narrow,
944 )
945 }
946 }
947 }
948 // Track cleared Wide position for damage expansion below
949 let clearedWideX = -1
950 if (
951 prevWidth === CellWidth.SpacerTail &&
952 cell.width !== CellWidth.SpacerTail
953 ) {
954 // Overwriting a SpacerTail: clear the orphaned Wide char at (x-1).
955 // Keeping the wide character with Narrow width would cause the terminal
956 // to still render it with width 2, desyncing the cursor model.
957 if (x > 0) {
958 const wideCI = ci - 2
959 if ((cells[wideCI + 1]! & WIDTH_MASK) === CellWidth.Wide) {
960 cells[wideCI] = EMPTY_CHAR_INDEX
961 cells[wideCI + 1] = packWord1(screen.emptyStyleId, 0, CellWidth.Narrow)
962 clearedWideX = x - 1
963 }
964 }
965 }
966
967 // Pack cell data into cells array
968 cells[ci] = internCharString(screen, cell.char)
969 cells[ci + 1] = packWord1(
970 cell.styleId,
971 internHyperlink(screen, cell.hyperlink),
972 cell.width,
973 )
974 screen.contentEnd[y] = Math.max(
975 screen.contentEnd[y] ?? 0,
976 x + (cell.width === CellWidth.Wide ? 2 : 1),
977 )

Callers 9

writeLineToScreenFunction · 0.85
output.test.tsFile · 0.85
makeFrameFunction · 0.85
makeFrameFunction · 0.85
screen.test.tsFile · 0.85
makeFrameFunction · 0.85
makeFrameFunction · 0.85
makeStyledLineFrameFunction · 0.85

Calls 4

packWord1Function · 0.85
internCharStringFunction · 0.85
internHyperlinkFunction · 0.85
maxMethod · 0.80

Tested by 5

makeFrameFunction · 0.68
makeFrameFunction · 0.68
makeFrameFunction · 0.68
makeFrameFunction · 0.68
makeStyledLineFrameFunction · 0.68