521
522
private _scanForGhostTextAdvanced(buffer: IBuffer, line: IBufferLine, cursorIndex: number): number {
524
>
let currentPos = buffer.cursorX; // Start scanning from the cursor position
525
>
526
>
// Map to store styles and their corresponding positions
527
>
const styleMap = new Map<string, number[]>();
528
>
529
>
// Identify the last non-whitespace character in the line
530
>
let lastNonWhitespaceCell = line.getCell(currentPos);
531
>
let nextCell: IBufferCell | undefined = lastNonWhitespaceCell;
532
>
533
>
// Scan from the cursor position to the end of the line
534
>
while (nextCell && currentPos < line.length) {
535
>
const styleKey = this._getCellStyleAsString(nextCell);
536
>
537
>
// Track all occurrences of each unique style in the line
538
>
styleMap.set(styleKey, [...(styleMap.get(styleKey) ?? []), currentPos]);
539
>
540
>
// Move to the next cell
541
>
nextCell = line.getCell(++currentPos);
542
>
543
>
// Update `lastNonWhitespaceCell` only if the new cell contains visible characters
544
>
if (nextCell?.getChars().trim().length) {
545
lastNonWhitespaceCell = nextCell;
546
}
548
>
549
>
// If there's no valid last non-whitespace cell OR the first and last styles match (indicating no ghost text)
550
>
if (!lastNonWhitespaceCell?.getChars().trim().length ||
551
>
this._cellStylesMatch(line.getCell(this._commandStartX), lastNonWhitespaceCell)) {
552
return -1;
553
}