mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
minor changes
This commit is contained in:
parent
d7c00addd5
commit
dd48db0ed3
4 changed files with 30 additions and 40 deletions
|
|
@ -28,6 +28,8 @@ export class DiffProvider implements vscode.CodeLensProvider {
|
|||
private _originalFileOfDocument: { [docUriStr: string]: string } = {}
|
||||
private _diffAreasOfDocument: { [docUriStr: string]: DiffArea[] } = {}
|
||||
private _diffsOfDocument: { [docUriStr: string]: Diff[] } = {}
|
||||
private _insetsOfDocument: { [docUriStr: string]: vscode.WebviewEditorInset[] } = {}
|
||||
|
||||
|
||||
private _diffareaidPool = 0
|
||||
private _diffidPool = 0
|
||||
|
|
@ -176,6 +178,10 @@ export class DiffProvider implements vscode.CodeLensProvider {
|
|||
// reset all diffs (we update them below)
|
||||
this._diffsOfDocument[docUriStr] = []
|
||||
|
||||
// reset all insets (we update them below)
|
||||
this._insetsOfDocument[docUriStr]?.forEach(inset => inset.dispose())
|
||||
this._insetsOfDocument[docUriStr] = []
|
||||
|
||||
// for each diffArea
|
||||
for (const diffArea of diffAreas) {
|
||||
|
||||
|
|
@ -215,20 +221,21 @@ export class DiffProvider implements vscode.CodeLensProvider {
|
|||
);
|
||||
|
||||
// update red highlighting
|
||||
// this._diffsOfDocument[docUriStr]
|
||||
// .filter(diff => diff.originalCode !== '')
|
||||
// .forEach(diff => {
|
||||
// const text = originalFile.split('\n').slice(diff.originalRange.start.line, diff.originalRange.start.line + 1).join('\n')
|
||||
// const height = text.split('\n').length
|
||||
// const line = diff.range.start.line - 1
|
||||
this._insetsOfDocument[docUriStr] = this._diffsOfDocument[docUriStr]
|
||||
.filter(diff => diff.originalCode !== '')
|
||||
.map(diff => {
|
||||
|
||||
// const inset = vscode.window.createWebviewTextEditorInset(editor, line, height);
|
||||
// updateWebviewHTML(inset.webview, this._extensionUri, { jsOutLocation: 'dist/webviews/diffline/index.js', cssOutLocation: 'dist/webviews/styles.css' },
|
||||
// { text }
|
||||
// )
|
||||
// create new inset
|
||||
const text = originalFile.split('\n').slice(diff.originalRange.start.line, diff.originalRange.end.line + 1).join('\n')
|
||||
const height = text.split('\n').length
|
||||
const line = diff.range.start.line - 1
|
||||
|
||||
|
||||
// })
|
||||
const inset = vscode.window.createWebviewTextEditorInset(editor, line, height);
|
||||
updateWebviewHTML(inset.webview, this._extensionUri, { jsOutLocation: 'dist/webviews/diffline/index.js', cssOutLocation: 'dist/webviews/styles.css' },
|
||||
{ text }
|
||||
)
|
||||
return inset
|
||||
})
|
||||
|
||||
// for each diffArea, highlight its sweepIndex in dark gray
|
||||
editor.setDecorations(
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
import * as vscode from 'vscode'
|
||||
|
||||
|
||||
export const readFileContentOfUri = async (uri: vscode.Uri): Promise<string> => {
|
||||
const document = await vscode.workspace.openTextDocument(uri);
|
||||
return document.getText().replace(/\r\n/g, '\n') ?? '' // Normalize line endings
|
||||
// export const readFileContentOfUri = async (uri: vscode.Uri): Promise<string> => {
|
||||
// const document = await vscode.workspace.openTextDocument(uri.fsPath);
|
||||
// return document.getText().replace(/\r\n/g, '\n') ?? '' // Normalize line endings
|
||||
// };
|
||||
|
||||
};
|
||||
|
||||
// this is the old version, which only reads the most recently saved version
|
||||
// export const readFileContentOfUri = async (uri: vscode.Uri) => {
|
||||
// return Buffer.from(await vscode.workspace.fs.readFile(uri)).toString('utf8')
|
||||
// .replace(/\r\n/g, '\n') // replace windows \r\n with \n
|
||||
// }
|
||||
// TODO this only accesses the most recently saved version; make it instead access the most recent version in the vscode editor
|
||||
export const readFileContentOfUri = async (uri: vscode.Uri) => {
|
||||
return Buffer.from(await vscode.workspace.fs.readFile(uri)).toString('utf8')
|
||||
.replace(/\r\n/g, '\n') // replace windows \r\n with \n
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,22 +3,6 @@
|
|||
import * as vscode from 'vscode';
|
||||
import { updateWebviewHTML as _updateWebviewHTML, updateWebviewHTML } from '../extensionLib/updateWebviewHTML';
|
||||
|
||||
// this comes from vscode.proposed.editorInsets.d.ts
|
||||
declare module 'vscode' {
|
||||
export interface WebviewEditorInset {
|
||||
readonly editor: vscode.TextEditor;
|
||||
readonly line: number;
|
||||
readonly height: number;
|
||||
readonly webview: vscode.Webview;
|
||||
readonly onDidDispose: Event<void>;
|
||||
dispose(): void;
|
||||
}
|
||||
export namespace window {
|
||||
export function createWebviewTextEditorInset(editor: vscode.TextEditor, line: number, height: number, options?: vscode.WebviewOptions): WebviewEditorInset;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export class CtrlKWebviewProvider {
|
||||
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ export const DiffLine = () => {
|
|||
const text = props.text
|
||||
|
||||
return <>
|
||||
<div>
|
||||
<pre>
|
||||
{text}
|
||||
</div>
|
||||
</pre>
|
||||
</>
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue