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

Method measureWrappedText

source code/utils/Cursor.ts:1295–1371  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1293 }
1294
1295 private measureWrappedText(): WrappedLine[] {
1296 const wrappedText = wrapAnsi(this.text, this.columns, {
1297 hard: true,
1298 trim: false,
1299 })
1300
1301 const wrappedLines: WrappedLine[] = []
1302 let searchOffset = 0
1303 let lastNewLinePos = -1
1304
1305 const lines = wrappedText.split('\n')
1306 for (let i = 0; i < lines.length; i++) {
1307 const text = lines[i]!
1308 const isPrecededByNewline = (startOffset: number) =>
1309 i === 0 || (startOffset > 0 && this.text[startOffset - 1] === '\n')
1310
1311 if (text.length === 0) {
1312 // For blank lines, find the next newline character after the last one
1313 lastNewLinePos = this.text.indexOf('\n', lastNewLinePos + 1)
1314
1315 if (lastNewLinePos !== -1) {
1316 const startOffset = lastNewLinePos
1317 const endsWithNewline = true
1318
1319 wrappedLines.push(
1320 new WrappedLine(
1321 text,
1322 startOffset,
1323 isPrecededByNewline(startOffset),
1324 endsWithNewline,
1325 ),
1326 )
1327 } else {
1328 // If we can't find another newline, this must be the end of text
1329 const startOffset = this.text.length
1330 wrappedLines.push(
1331 new WrappedLine(
1332 text,
1333 startOffset,
1334 isPrecededByNewline(startOffset),
1335 false,
1336 ),
1337 )
1338 }
1339 } else {
1340 // For non-blank lines, find the text in this.text
1341 const startOffset = this.text.indexOf(text, searchOffset)
1342
1343 if (startOffset === -1) {
1344 throw new Error('Failed to find wrapped line in text')
1345 }
1346
1347 searchOffset = startOffset + text.length
1348
1349 // Check if this line ends with a newline in this.text
1350 const potentialNewlinePos = startOffset + text.length
1351 const endsWithNewline =
1352 potentialNewlinePos < this.text.length &&

Callers 1

wrappedLinesMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected