mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
This reverts commit bfe6dcb6f3
.
This commit is contained in:
parent
63ce9c034f
commit
941450fd05
|
@ -88,6 +88,7 @@ export interface IChatRendererDelegate {
|
|||
}
|
||||
|
||||
export class ChatListItemRenderer extends Disposable implements ITreeRenderer<ChatTreeItem, FuzzyScore, IChatListItemTemplate> {
|
||||
static readonly cursorCharacter = '\u258c';
|
||||
static readonly ID = 'item';
|
||||
|
||||
private readonly codeBlocksByResponseId = new Map<string, IChatCodeBlockInfo[]>();
|
||||
|
@ -367,7 +368,12 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
|
|||
isFullyRendered: renderValue.isFullString
|
||||
};
|
||||
|
||||
const result = this.renderMarkdown(new MarkdownString(renderValue.value), element, disposables, templateData, true);
|
||||
// Don't add the cursor if it will go after a codeblock, since this will always cause layout shifting
|
||||
// when the codeblock is the last thing in the response, and that happens often.
|
||||
const plusCursor = renderValue.value.match(/```\s*$/) ?
|
||||
renderValue.value :
|
||||
renderValue.value + ` ${ChatListItemRenderer.cursorCharacter}`;
|
||||
const result = this.renderMarkdown(new MarkdownString(plusCursor), element, disposables, templateData, true);
|
||||
// Doing the progressive render
|
||||
dom.clearNode(templateData.value);
|
||||
templateData.value.appendChild(result.element);
|
||||
|
@ -752,16 +758,28 @@ class CodeBlockPart extends Disposable implements IChatResultCodeBlockPart {
|
|||
}
|
||||
|
||||
private setText(newText: string): void {
|
||||
const currentText = this.textModel.getLinesContent().join('\n');
|
||||
let currentText = this.textModel.getLinesContent().join('\n');
|
||||
if (newText === currentText) {
|
||||
return;
|
||||
}
|
||||
|
||||
let removedChars = 0;
|
||||
if (currentText.endsWith(` ${ChatListItemRenderer.cursorCharacter}`)) {
|
||||
removedChars = 2;
|
||||
} else if (currentText.endsWith(ChatListItemRenderer.cursorCharacter)) {
|
||||
removedChars = 1;
|
||||
}
|
||||
|
||||
if (removedChars > 0) {
|
||||
currentText = currentText.slice(0, currentText.length - removedChars);
|
||||
}
|
||||
|
||||
if (newText.startsWith(currentText)) {
|
||||
const text = newText.slice(currentText.length);
|
||||
const lastLine = this.textModel.getLineCount();
|
||||
const lastCol = this.textModel.getLineMaxColumn(lastLine);
|
||||
this.textModel.applyEdits([{ range: new Range(lastLine, lastCol, lastLine, lastCol), text }]);
|
||||
const insertAtCol = lastCol - removedChars;
|
||||
this.textModel.applyEdits([{ range: new Range(lastLine, insertAtCol, lastLine, lastCol), text }]);
|
||||
} else {
|
||||
// console.log(`Failed to optimize setText`);
|
||||
this.textModel.setValue(newText);
|
||||
|
|
Loading…
Reference in a new issue