MCPcopy Create free account
hub / github.com/freecodexyz/free-code / measureWrappedText

Method measureWrappedText

src/utils/Cursor.ts:1293–1369  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

wrappedLinesMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected