Skip to content

Commit

Permalink
detect ghost text more broadly (microsoft#240427)
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge authored Feb 11, 2025
1 parent f12fa05 commit 4d1bbf9
Showing 1 changed file with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
if (proceedWithGhostTextCheck) {
let potentialGhostIndexOffset = 0;
let x = buffer.cursorX;
const cursorCell = line.getCell(buffer.cursorX - 1);

while (x < line.length) {
const cell = line.getCell(x++);
if (!cell || cell.getCode() === 0) {
Expand All @@ -440,12 +442,49 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
if (this._isCellStyledLikeGhostText(cell)) {
ghostTextIndex = cursorIndex + potentialGhostIndexOffset;
break;
} else if (!this._cellStylesMatch(cursorCell, cell)) {
const ghostTextCell = cell;
// Verify that all chars for the rest of the line match this
// ghost text style
while (x < line.length) {
const cell = line.getCell(x++);
if (!cell || cell.getCode() === 0) {
break;
}

if (!this._cellStylesMatch(ghostTextCell, cell)) {
return -1;
}

}
ghostTextIndex = cursorIndex + potentialGhostIndexOffset;
return ghostTextIndex;
}

potentialGhostIndexOffset += cell.getChars().length;
}
}

return ghostTextIndex;

}

private _cellStylesMatch(a: IBufferCell | undefined, b: IBufferCell | undefined): boolean {
if (!a || !b) {
return false;
}
return a.getFgColor() === b.getFgColor()
&& a.getBgColor() === b.getBgColor()
&& a.isBold() === b.isBold()
&& a.isItalic() === b.isItalic()
&& a.isDim() === b.isDim()
&& a.isUnderline() === b.isUnderline()
&& a.isBlink() === b.isBlink()
&& a.isInverse() === b.isInverse()
&& a.isInvisible() === b.isInvisible()
&& a.isStrikethrough() === b.isStrikethrough()
&& a.isOverline() === b.isOverline()
&& a?.getBgColorMode() === b?.getBgColorMode()
&& a?.getFgColorMode() === b?.getFgColorMode();
}

private _trimContinuationPrompt(lineText: string): string {
Expand Down

0 comments on commit 4d1bbf9

Please sign in to comment.