Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses diff editor v2 in inline chat. #187928

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
}));
}

public getContentHeight() {
return this._editors.modified.getContentHeight();
}

protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: Readonly<IEditorConstructionOptions>, editorWidgetOptions: ICodeEditorWidgetOptions): CodeEditorWidget {
const editor = instantiationService.createInstance(CodeEditorWidget, container, options, editorWidgetOptions);
return editor;
Expand Down
47 changes: 47 additions & 0 deletions src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry';
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2';

export class EmbeddedCodeEditorWidget extends CodeEditorWidget {

Expand Down Expand Up @@ -67,6 +68,9 @@ export class EmbeddedCodeEditorWidget extends CodeEditorWidget {
}
}

/**
* @deprecated Use EmbeddedDiffEditorWidget2 instead.
*/
export class EmbeddedDiffEditorWidget extends DiffEditorWidget {

private readonly _parentEditor: ICodeEditor;
Expand Down Expand Up @@ -111,3 +115,46 @@ export class EmbeddedDiffEditorWidget extends DiffEditorWidget {
super.updateOptions(this._overwriteOptions);
}
}

/**
* TODO: Rename to EmbeddedDiffEditorWidget once EmbeddedDiffEditorWidget is removed.
*/
export class EmbeddedDiffEditorWidget2 extends DiffEditorWidget2 {

private readonly _parentEditor: ICodeEditor;
private readonly _overwriteOptions: IDiffEditorOptions;

constructor(
domElement: HTMLElement,
options: Readonly<IDiffEditorConstructionOptions>,
codeEditorWidgetOptions: IDiffCodeEditorWidgetOptions,
parentEditor: ICodeEditor,
@IContextKeyService contextKeyService: IContextKeyService,
@IInstantiationService instantiationService: IInstantiationService,
@ICodeEditorService codeEditorService: ICodeEditorService,
) {
super(domElement, parentEditor.getRawOptions(), codeEditorWidgetOptions, contextKeyService, instantiationService, codeEditorService);

this._parentEditor = parentEditor;
this._overwriteOptions = options;

// Overwrite parent's options
super.updateOptions(this._overwriteOptions);

this._register(parentEditor.onDidChangeConfiguration(e => this._onParentConfigurationChanged(e)));
}

getParentEditor(): ICodeEditor {
return this._parentEditor;
}

private _onParentConfigurationChanged(e: ConfigurationChangedEvent): void {
super.updateOptions(this._parentEditor.getRawOptions());
super.updateOptions(this._overwriteOptions);
}

override updateOptions(newOptions: IEditorOptions): void {
objects.mixin(this._overwriteOptions, newOptions, true);
super.updateOptions(this._overwriteOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Dimension, h } from 'vs/base/browser/dom';
import { DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
import { assertType } from 'vs/base/common/types';
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
import { EmbeddedCodeEditorWidget, EmbeddedDiffEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
import { EmbeddedCodeEditorWidget, EmbeddedDiffEditorWidget2 } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { Range } from 'vs/editor/common/core/range';
import { ITextModel } from 'vs/editor/common/model';
Expand Down Expand Up @@ -62,7 +62,7 @@ export class InlineChatLivePreviewWidget extends ZoneWidget {
.getEditorContributions()
.filter(c => c.id !== INLINE_CHAT_ID && c.id !== FoldingController.ID);

this._diffEditor = instantiationService.createInstance(EmbeddedDiffEditorWidget, this._elements.domNode, {
this._diffEditor = instantiationService.createInstance(EmbeddedDiffEditorWidget2, this._elements.domNode, {
scrollbar: { useShadows: false, alwaysConsumeMouseWheel: false },
scrollBeyondLastLine: false,
renderMarginRevertIcon: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
import { SnippetController2 } from 'vs/editor/contrib/snippet/browser/snippetController2';
import { IModelService } from 'vs/editor/common/services/model';
import { URI } from 'vs/base/common/uri';
import { EmbeddedCodeEditorWidget, EmbeddedDiffEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
import { EmbeddedCodeEditorWidget, EmbeddedDiffEditorWidget2 } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
import { HiddenItemStrategy, MenuWorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';
import { ProgressBar } from 'vs/base/browser/ui/progressbar/progressbar';
import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestController';
Expand Down Expand Up @@ -164,7 +164,7 @@ export class InlineChatWidget {

private readonly _progressBar: ProgressBar;

private readonly _previewDiffEditor: IdleValue<EmbeddedDiffEditorWidget>;
private readonly _previewDiffEditor: IdleValue<EmbeddedDiffEditorWidget2>;
private readonly _previewDiffModel = this._store.add(new MutableDisposable());

private readonly _previewCreateTitle: ResourceLabel;
Expand Down Expand Up @@ -329,7 +329,7 @@ export class InlineChatWidget {
this._store.add(feedbackToolbar);

// preview editors
this._previewDiffEditor = new IdleValue(() => this._store.add(_instantiationService.createInstance(EmbeddedDiffEditorWidget, this._elements.previewDiff, _previewEditorEditorOptions, { modifiedEditor: codeEditorWidgetOptions, originalEditor: codeEditorWidgetOptions }, parentEditor)));
this._previewDiffEditor = new IdleValue(() => this._store.add(_instantiationService.createInstance(EmbeddedDiffEditorWidget2, this._elements.previewDiff, _previewEditorEditorOptions, { modifiedEditor: codeEditorWidgetOptions, originalEditor: codeEditorWidgetOptions }, parentEditor)));

this._previewCreateTitle = this._store.add(_instantiationService.createInstance(ResourceLabel, this._elements.previewCreateTitle, { supportIcons: true }));
this._previewCreateEditor = new IdleValue(() => this._store.add(_instantiationService.createInstance(EmbeddedCodeEditorWidget, this._elements.previewCreate, _previewEditorEditorOptions, codeEditorWidgetOptions, parentEditor)));
Expand Down Expand Up @@ -408,7 +408,7 @@ export class InlineChatWidget {
const base = getTotalHeight(this._elements.progress) + getTotalHeight(this._elements.status);
const editorHeight = this._inputEditor.getContentHeight() + 12 /* padding and border */;
const markdownMessageHeight = getTotalHeight(this._elements.markdownMessage);
const previewDiffHeight = this._previewDiffEditor.value.getModel().modified ? 12 + Math.min(300, Math.max(0, this._previewDiffEditor.value.getContentHeight())) : 0;
const previewDiffHeight = this._previewDiffEditor.value.getModel() ? 12 + Math.min(300, Math.max(0, this._previewDiffEditor.value.getContentHeight())) : 0;
const previewCreateTitleHeight = getTotalHeight(this._elements.previewCreateTitle);
const previewCreateHeight = this._previewCreateEditor.value.getModel() ? 18 + Math.min(300, Math.max(0, this._previewCreateEditor.value.getContentHeight())) : 0;
return base + editorHeight + markdownMessageHeight + previewDiffHeight + previewCreateTitleHeight + previewCreateHeight + 18 /* padding */ + 8 /*shadow*/;
Expand Down