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

Method offsetAtDisplayWidth

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

1243 * Find the string offset that corresponds to a target display width.
1244 */
1245 private offsetAtDisplayWidth(targetWidth: number): number {
1246 if (targetWidth <= 0) return 0
1247
1248 let currentWidth = 0
1249 const boundaries = this.getGraphemeBoundaries()
1250
1251 // Iterate through grapheme boundaries
1252 for (let i = 0; i < boundaries.length - 1; i++) {
1253 const start = boundaries[i]
1254 const end = boundaries[i + 1]
1255 if (start === undefined || end === undefined) continue
1256 const segment = this.text.substring(start, end)
1257 const segmentWidth = stringWidth(segment)
1258
1259 if (currentWidth + segmentWidth > targetWidth) {
1260 return start
1261 }
1262 currentWidth += segmentWidth
1263 }
1264
1265 return this.text.length
1266 }
1267
1268 private measureWrappedText(): WrappedLine[] {
1269 const wrappedText = wrapAnsi(this.text, this.columns, {

Callers 1

Calls 1

getGraphemeBoundariesMethod · 0.95

Tested by

no test coverage detected