From 40ba9eaf82a1386ccacf5046c072df3d131d5284 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 12 Jun 2023 10:50:33 -0700 Subject: calculate diff and highlight changes --- extension/src/continueIdeClient.ts | 31 ++++++++++++++++++++++++++++++- extension/src/decorations.ts | 19 +++++++++++++------ 2 files changed, 43 insertions(+), 7 deletions(-) (limited to 'extension/src') diff --git a/extension/src/continueIdeClient.ts b/extension/src/continueIdeClient.ts index bbaf5f08..c395ae0e 100644 --- a/extension/src/continueIdeClient.ts +++ b/extension/src/continueIdeClient.ts @@ -13,6 +13,7 @@ import { FileEditWithFullContents } from "../schema/FileEditWithFullContents"; import fs = require("fs"); import { WebsocketMessenger } from "./util/messenger"; import { CapturedTerminal } from "./terminal/terminalEmulator"; +import { decorationManager } from "./decorations"; class IdeProtocolClient { private messenger: WebsocketMessenger | null = null; @@ -281,8 +282,36 @@ class IdeProtocolClient { edit.range.start.line, edit.range.start.character, edit.range.end.line, - edit.range.end.character + 1 + edit.range.end.character ); + const decorationKey = + edit.replacement === "" + ? { + editorUri: editor.document.uri.fsPath, + options: { + range: new vscode.Range( + new vscode.Position(range.start.line, 0), + new vscode.Position(range.end.line + 1, 0) + ), + // after: { + // contentText: "Removed", + // }, + }, + decorationType: vscode.window.createTextEditorDecorationType({ + backgroundColor: "rgba(255, 0, 0, 0.2)", + }), + } + : { + editorUri: editor.document.uri.fsPath, + options: { + range, + }, + decorationType: vscode.window.createTextEditorDecorationType({ + backgroundColor: "rgba(66, 105, 55, 1.0)", + isWholeLine: true, + }), + }; + decorationManager.addDecoration(decorationKey); editor.edit((editBuilder) => { this._makingEdit += 2; // editBuilder.replace takes 2 edits: delete and insert editBuilder.replace(range, edit.replacement); diff --git a/extension/src/decorations.ts b/extension/src/decorations.ts index 456f0c10..d2c94135 100644 --- a/extension/src/decorations.ts +++ b/extension/src/decorations.ts @@ -94,15 +94,22 @@ class DecorationManager { decorationTypes = new Map(); decorationTypes.set(key.decorationType, [key.options]); this.editorToDecorations.set(key.editorUri, decorationTypes); - } - - const decorations = decorationTypes.get(key.decorationType); - if (!decorations) { - decorationTypes.set(key.decorationType, [key.options]); } else { - decorations.push(key.options); + const decorations = decorationTypes.get(key.decorationType); + if (!decorations) { + decorationTypes.set(key.decorationType, [key.options]); + } else { + decorations.push(key.options); + } } + this.rerenderDecorations(key.editorUri, key.decorationType); + + vscode.window.onDidChangeTextEditorSelection((event) => { + if (event.textEditor.document.fileName === key.editorUri) { + this.deleteAllDecorations(key.editorUri); + } + }); } deleteDecoration(key: DecorationKey) { -- cgit v1.2.3-70-g09d2