MCPcopy Index your code
hub / github.com/codeaashu/claude-code / applySearchHighlight

Function applySearchHighlight

src/ink/searchHighlight.ts:27–93  ·  view source on GitHub ↗
(
  screen: Screen,
  query: string,
  stylePool: StylePool,
)

Source from the content-addressed store, hash-verified

25 * full-frame damage when true).
26 */
27export function applySearchHighlight(
28 screen: Screen,
29 query: string,
30 stylePool: StylePool,
31): boolean {
32 if (!query) return false
33 const lq = query.toLowerCase()
34 const qlen = lq.length
35 const w = screen.width
36 const noSelect = screen.noSelect
37 const height = screen.height
38
39 let applied = false
40 for (let row = 0; row < height; row++) {
41 const rowOff = row * w
42 // Build row text (already lowercased) + code-unit→cell-index map.
43 // Three skip conditions, all aligned with setCellStyleId /
44 // extractRowText (selection.ts):
45 // - SpacerTail: 2nd cell of a wide char, no char of its own
46 // - SpacerHead: end-of-line padding when a wide char wraps
47 // - noSelect: gutters (⎿, line numbers) — same exclusion as
48 // applySelectionOverlay. "Highlight what you see" still holds for
49 // content; gutters aren't search targets.
50 // Lowercasing per-char (not on the joined string at the end) means
51 // codeUnitToCell maps positions in the LOWERCASED text — U+0130
52 // (Turkish İ) lowercases to 2 code units, so lowering the joined
53 // string would desync indexOf positions from the map.
54 let text = ''
55 const colOf: number[] = []
56 const codeUnitToCell: number[] = []
57 for (let col = 0; col < w; col++) {
58 const idx = rowOff + col
59 const cell = cellAtIndex(screen, idx)
60 if (
61 cell.width === CellWidth.SpacerTail ||
62 cell.width === CellWidth.SpacerHead ||
63 noSelect[idx] === 1
64 ) {
65 continue
66 }
67 const lc = cell.char.toLowerCase()
68 const cellIdx = colOf.length
69 for (let i = 0; i < lc.length; i++) {
70 codeUnitToCell.push(cellIdx)
71 }
72 text += lc
73 colOf.push(col)
74 }
75
76 let pos = text.indexOf(lq)
77 while (pos >= 0) {
78 applied = true
79 const startCi = codeUnitToCell[pos]!
80 const endCi = codeUnitToCell[pos + qlen - 1]!
81 for (let ci = startCi; ci <= endCi; ci++) {
82 const col = colOf[ci]!
83 const cell = cellAtIndex(screen, rowOff + col)
84 setCellStyleId(screen, col, row, stylePool.withInverse(cell.styleId))

Callers 1

onRenderMethod · 0.85

Calls 4

cellAtIndexFunction · 0.85
setCellStyleIdFunction · 0.85
withInverseMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected