MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / offsetAtDisplayWidth

Method offsetAtDisplayWidth

source code/utils/Cursor.ts:1272–1293  ·  view source on GitHub ↗

* Find the string offset that corresponds to a target display width.

(targetWidth: number)

Source from the content-addressed store, hash-verified

1270 * Find the string offset that corresponds to a target display width.
1271 */
1272 private offsetAtDisplayWidth(targetWidth: number): number {
1273 if (targetWidth <= 0) return 0
1274
1275 let currentWidth = 0
1276 const boundaries = this.getGraphemeBoundaries()
1277
1278 // Iterate through grapheme boundaries
1279 for (let i = 0; i < boundaries.length - 1; i++) {
1280 const start = boundaries[i]
1281 const end = boundaries[i + 1]
1282 if (start === undefined || end === undefined) continue
1283 const segment = this.text.substring(start, end)
1284 const segmentWidth = stringWidth(segment)
1285
1286 if (currentWidth + segmentWidth > targetWidth) {
1287 return start
1288 }
1289 currentWidth += segmentWidth
1290 }
1291
1292 return this.text.length
1293 }
1294
1295 private measureWrappedText(): WrappedLine[] {
1296 const wrappedText = wrapAnsi(this.text, this.columns, {

Callers 1

Calls 1

getGraphemeBoundariesMethod · 0.95

Tested by

no test coverage detected