MCPcopy
hub / github.com/codeaashu/claude-code / clearRegion

Function clearRegion

src/ink/screen.ts:959–1048  ·  view source on GitHub ↗
(
  screen: Screen,
  regionX: number,
  regionY: number,
  regionWidth: number,
  regionHeight: number,
)

Source from the content-addressed store, hash-verified

957 * Handles wide character boundary cleanup at region edges.
958 */
959export function clearRegion(
960 screen: Screen,
961 regionX: number,
962 regionY: number,
963 regionWidth: number,
964 regionHeight: number,
965): void {
966 const startX = Math.max(0, regionX)
967 const startY = Math.max(0, regionY)
968 const maxX = Math.min(regionX + regionWidth, screen.width)
969 const maxY = Math.min(regionY + regionHeight, screen.height)
970 if (startX >= maxX || startY >= maxY) return
971
972 const cells = screen.cells
973 const cells64 = screen.cells64
974 const screenWidth = screen.width
975 const rowBase = startY * screenWidth
976 let damageMinX = startX
977 let damageMaxX = maxX
978
979 // EMPTY_CELL_VALUE (0n) matches the zero-initialized state:
980 // word0=EMPTY_CHAR_INDEX(0), word1=packWord1(0,0,0)=0
981 if (startX === 0 && maxX === screenWidth) {
982 // Full-width: single fill, no boundary checks needed
983 cells64.fill(
984 EMPTY_CELL_VALUE,
985 rowBase,
986 rowBase + (maxY - startY) * screenWidth,
987 )
988 } else {
989 // Partial-width: single loop handles boundary cleanup and fill per row.
990 const stride = screenWidth << 1 // 2 Int32s per cell
991 const rowLen = maxX - startX
992 const checkLeft = startX > 0
993 const checkRight = maxX < screenWidth
994 let leftEdge = (rowBase + startX) << 1
995 let rightEdge = (rowBase + maxX - 1) << 1
996 let fillStart = rowBase + startX
997
998 for (let y = startY; y < maxY; y++) {
999 // Left boundary: if cell at startX is a SpacerTail, the Wide char
1000 // at startX-1 (outside the region) will be orphaned. Clear it.
1001 if (checkLeft) {
1002 // leftEdge points to word0 of cell at startX; +1 is its word1
1003 if ((cells[leftEdge + 1]! & WIDTH_MASK) === CellWidth.SpacerTail) {
1004 // word1 of cell at startX-1 is leftEdge-1; word0 is leftEdge-2
1005 const prevW1 = leftEdge - 1
1006 if ((cells[prevW1]! & WIDTH_MASK) === CellWidth.Wide) {
1007 cells[prevW1 - 1] = EMPTY_CHAR_INDEX
1008 cells[prevW1] = packWord1(screen.emptyStyleId, 0, CellWidth.Narrow)
1009 damageMinX = startX - 1
1010 }
1011 }
1012 }
1013
1014 // Right boundary: if cell at maxX-1 is Wide, its SpacerTail at maxX
1015 // (outside the region) will be orphaned. Clear it.
1016 if (checkRight) {

Callers

nothing calls this directly

Calls 4

packWord1Function · 0.85
unionRectFunction · 0.85
maxMethod · 0.80
fillMethod · 0.80

Tested by

no test coverage detected