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

Method snapToGraphemeBoundary

src/utils/Cursor.ts:1516–1529  ·  view source on GitHub ↗

* Snap an arbitrary code-unit offset to the start of the containing grapheme. * If offset is already on a boundary, returns it unchanged.

(offset: number)

Source from the content-addressed store, hash-verified

1514 * If offset is already on a boundary, returns it unchanged.
1515 */
1516 snapToGraphemeBoundary(offset: number): number {
1517 if (offset <= 0) return 0
1518 if (offset >= this.text.length) return this.text.length
1519 const boundaries = this.getGraphemeBoundaries()
1520 // Binary search for largest boundary <= offset
1521 let lo = 0
1522 let hi = boundaries.length - 1
1523 while (lo < hi) {
1524 const mid = (lo + hi + 1) >> 1
1525 if (boundaries[mid]! <= offset) lo = mid
1526 else hi = mid - 1
1527 }
1528 return boundaries[lo]!
1529 }
1530}
1531

Callers 1

Calls 1

getGraphemeBoundariesMethod · 0.95

Tested by

no test coverage detected