mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
renders oldText nicely!
This commit is contained in:
parent
5acc53311d
commit
584d026256
5 changed files with 59 additions and 77 deletions
|
|
@ -146,7 +146,7 @@ We're always glad to talk about new ideas, help you get set up, and make sure yo
|
|||
|
||||
## Submitting a Pull Request
|
||||
|
||||
Please submit a pull request once you've made a change. You don't need to submit an issue.
|
||||
Please submit a pull request once you've made a change. You don't need to submit an issue.
|
||||
|
||||
Please don't use AI to write your PR 🙂.
|
||||
|
||||
|
|
|
|||
8
extensions/void/package-lock.json
generated
8
extensions/void/package-lock.json
generated
|
|
@ -6024,14 +6024,6 @@
|
|||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/monaco-editor": {
|
||||
"version": "0.52.0",
|
||||
"resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.52.0.tgz",
|
||||
"integrity": "sha512-OeWhNpABLCeTqubfqLMXGsqf6OmPU6pHM85kF3dhy6kq5hnhuVS1p3VrEW/XhWHc71P2tHyS5JFySD8mgs1crw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
|
|
|
|||
|
|
@ -1,17 +1,13 @@
|
|||
// This file was added by the Void team
|
||||
|
||||
// src/vs/editor/browser/services/inlineDiffService.ts
|
||||
import { Disposable } from '../../../base/common/lifecycle.js';
|
||||
import { registerSingleton, InstantiationType } from '../../../platform/instantiation/common/extensions.js';
|
||||
import { createDecorator } from '../../../platform/instantiation/common/instantiation.js';
|
||||
import { IModelDecorationOptions, IModelDeltaDecoration } from '../../common/model.js';
|
||||
import { IModelDeltaDecoration } from '../../common/model.js';
|
||||
import { ICodeEditor, IViewZone } from '../editorBrowser.js';
|
||||
import { IRange } from '../../common/core/range.js';
|
||||
|
||||
import { EditorOption } from '../../common/config/editorOptions.js';
|
||||
|
||||
export interface IInlineDiffService {
|
||||
readonly _serviceBrand: undefined;
|
||||
|
||||
addDiff(editor: ICodeEditor, originalText: string, modifiedRange: IRange): void;
|
||||
removeDiffs(editor: ICodeEditor): void;
|
||||
}
|
||||
|
|
@ -23,78 +19,94 @@ class InlineDiffService extends Disposable implements IInlineDiffService {
|
|||
private readonly _diffZones = new Map<ICodeEditor, string[]>();
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private static readonly ADDED_DECORATION: IModelDecorationOptions = {
|
||||
className: 'inline-diff-added',
|
||||
description: 'inline-diff-added',
|
||||
isWholeLine: false,
|
||||
minimap: {
|
||||
color: { id: 'minimapGutter.addedBackground' },
|
||||
position: 2
|
||||
},
|
||||
overviewRuler: {
|
||||
color: { id: 'editorOverviewRuler.addedForeground' },
|
||||
position: 7
|
||||
}
|
||||
};
|
||||
|
||||
constructor(
|
||||
|
||||
) {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public addDiff: IInlineDiffService['addDiff'] = (editor, originalText, modifiedRange) => {
|
||||
|
||||
public addDiff: IInlineDiffService['addDiff'] = (editor, originalText, modifiedRange) => {
|
||||
// Clear existing diffs
|
||||
this.removeDiffs(editor);
|
||||
|
||||
// Add decoration for modified text
|
||||
const decorations: IModelDeltaDecoration[] = [{
|
||||
// green decoration
|
||||
const greenDecoration: IModelDeltaDecoration[] = [{
|
||||
range: modifiedRange,
|
||||
options: InlineDiffService.ADDED_DECORATION
|
||||
options: {
|
||||
className: 'line-insert', // .monaco-editor .line-insert
|
||||
description: 'line-insert',
|
||||
isWholeLine: true,
|
||||
minimap: {
|
||||
color: { id: 'inlineDiff.minimapGutter.addedBackground' },
|
||||
position: 2
|
||||
},
|
||||
overviewRuler: {
|
||||
color: { id: 'inlineDiff.editorOverviewRuler.addedForeground' },
|
||||
position: 7
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
const newDecorations = editor.deltaDecorations([], decorations);
|
||||
this._diffDecorations.set(editor, newDecorations);
|
||||
this._diffDecorations.set(editor, editor.deltaDecorations([], greenDecoration));
|
||||
|
||||
// Add view zone for original text
|
||||
// red in a view zone
|
||||
editor.changeViewZones(accessor => {
|
||||
const domNode = document.createElement('div');
|
||||
domNode.className = 'inline-diff-deleted monaco-editor';
|
||||
// Get the editor's font info
|
||||
const fontInfo = editor.getOption(EditorOption.fontInfo);
|
||||
|
||||
// Create inner container for proper padding
|
||||
const innerContainer = document.createElement('div');
|
||||
innerContainer.className = 'view-line';
|
||||
innerContainer.textContent = originalText;
|
||||
domNode.appendChild(innerContainer);
|
||||
const domNode = document.createElement('div');
|
||||
domNode.className = 'monaco-editor view-zones line-delete monaco-mouse-cursor-text';
|
||||
domNode.style.fontSize = `${fontInfo.fontSize}px`;
|
||||
domNode.style.fontFamily = fontInfo.fontFamily;
|
||||
domNode.style.lineHeight = `100%`;
|
||||
|
||||
// div
|
||||
const lineContent = document.createElement('div');
|
||||
lineContent.className = 'view-line'; // .monaco-editor .inline-deleted-text
|
||||
|
||||
// span
|
||||
const contentSpan = document.createElement('span');
|
||||
|
||||
// span
|
||||
const codeSpan = document.createElement('span');
|
||||
codeSpan.className = 'mtk1'; // char-delete
|
||||
codeSpan.textContent = originalText;
|
||||
|
||||
// Mount
|
||||
contentSpan.appendChild(codeSpan);
|
||||
lineContent.appendChild(contentSpan);
|
||||
domNode.appendChild(lineContent);
|
||||
|
||||
const viewZone: IViewZone = {
|
||||
afterLineNumber: modifiedRange.startLineNumber - 1,
|
||||
heightInLines: originalText.split('\n').length,
|
||||
heightInLines: 1,
|
||||
domNode: domNode,
|
||||
suppressMouseDown: true,
|
||||
marginDomNode: this.createGutterElement(editor)
|
||||
marginDomNode: this.createGutterElement()
|
||||
};
|
||||
|
||||
const zoneId = accessor.addZone(viewZone);
|
||||
// editor.layout();
|
||||
this._diffZones.set(editor, [zoneId]);
|
||||
});
|
||||
}
|
||||
|
||||
private createGutterElement(editor: ICodeEditor): HTMLElement {
|
||||
private createGutterElement(): HTMLElement {
|
||||
const gutterDiv = document.createElement('div');
|
||||
gutterDiv.className = 'inline-diff-gutter';
|
||||
gutterDiv.innerHTML = '<div class="inline-diff-deleted-gutter">-</div>';
|
||||
|
||||
const minusDiv = document.createElement('div');
|
||||
minusDiv.className = 'inline-diff-deleted-gutter';
|
||||
minusDiv.textContent = '-';
|
||||
|
||||
gutterDiv.appendChild(minusDiv);
|
||||
return gutterDiv;
|
||||
}
|
||||
|
||||
public removeDiffs(editor: ICodeEditor): void {
|
||||
// Clear decorations
|
||||
const decorationIds = this._diffDecorations.get(editor) || [];
|
||||
editor.deltaDecorations(decorationIds, []);
|
||||
this._diffDecorations.delete(editor);
|
||||
|
||||
// Clear view zones
|
||||
editor.changeViewZones(accessor => {
|
||||
const zoneIds = this._diffZones.get(editor) || [];
|
||||
zoneIds.forEach(id => accessor.removeZone(id));
|
||||
|
|
@ -109,7 +121,4 @@ class InlineDiffService extends Disposable implements IInlineDiffService {
|
|||
}
|
||||
}
|
||||
|
||||
// Register the service
|
||||
registerSingleton(IInlineDiffService, InlineDiffService, InstantiationType.Eager);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -426,26 +426,4 @@
|
|||
}
|
||||
}
|
||||
|
||||
/* Void added this: */
|
||||
.inline-diff-deleted {
|
||||
background-color: var(--vscode-diffEditor-removedTextBackground);
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.inline-diff-added {
|
||||
background-color: var(--vscode-diffEditor-insertedTextBackground);
|
||||
}
|
||||
|
||||
.inline-diff-gutter {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.inline-diff-deleted-gutter {
|
||||
opacity: 0.7;
|
||||
padding-left: 4px;
|
||||
}
|
||||
|
||||
.view-line {
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,6 +90,9 @@ import './mainThreadProfileContentHandlers.js';
|
|||
import './mainThreadAiRelatedInformation.js';
|
||||
import './mainThreadAiEmbeddingVector.js';
|
||||
|
||||
// Void added this:
|
||||
import './mainThreadInlineDiff.js';
|
||||
|
||||
export class ExtensionPoints implements IWorkbenchContribution {
|
||||
|
||||
static readonly ID = 'workbench.contrib.extensionPoints';
|
||||
|
|
|
|||
Loading…
Reference in a new issue