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

Method offsetAtDisplayWidth

src/utils/Cursor.ts:1270–1291  ·  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

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

Callers 1

Calls 1

getGraphemeBoundariesMethod · 0.95

Tested by

no test coverage detected