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

Quick diff should not run in diff editor #193978

Merged
merged 1 commit into from
Sep 25, 2023
Merged
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
48 changes: 28 additions & 20 deletions src/vs/workbench/contrib/scm/browser/dirtydiffDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { basename } from 'vs/base/common/resources';
import { MenuId, IMenuService, IMenu, MenuItemAction, MenuRegistry } from 'vs/platform/actions/common/actions';
import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IEditorModel, ScrollType, IEditorContribution, IDiffEditorModel } from 'vs/editor/common/editorCommon';
import { ScrollType, IEditorContribution, IDiffEditorModel, IEditorModel, IEditorDecorationsCollection } from 'vs/editor/common/editorCommon';
import { OverviewRulerLane, ITextModel, IModelDecorationOptions, MinimapPosition, shouldSynchronizeModel } from 'vs/editor/common/model';
import { equals, sortedDiff } from 'vs/base/common/arrays';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
Expand Down Expand Up @@ -73,7 +73,7 @@ class DiffActionRunner extends ActionRunner {
}

export interface IModelRegistry {
getModel(editorModel: IEditorModel): DirtyDiffModel | undefined;
getModel(editorModel: IEditorModel, codeEditor: ICodeEditor): DirtyDiffModel | undefined;
}

export interface DirtyDiffContribution extends IEditorContribution {
Expand Down Expand Up @@ -593,7 +593,7 @@ export class GotoPreviousChangeAction extends EditorAction {
}

const lineNumber = outerEditor.getPosition().lineNumber;
const model = controller.modelRegistry.getModel(outerEditor.getModel());
const model = controller.modelRegistry.getModel(outerEditor.getModel(), outerEditor);
if (!model || model.changes.length === 0) {
return;
}
Expand Down Expand Up @@ -635,7 +635,7 @@ export class GotoNextChangeAction extends EditorAction {
}

const lineNumber = outerEditor.getPosition().lineNumber;
const model = controller.modelRegistry.getModel(outerEditor.getModel());
const model = controller.modelRegistry.getModel(outerEditor.getModel(), outerEditor);

if (!model || model.changes.length === 0) {
return;
Expand Down Expand Up @@ -845,7 +845,7 @@ export class DirtyDiffController extends Disposable implements DirtyDiffContribu
return false;
}

const model = this.modelRegistry.getModel(editorModel);
const model = this.modelRegistry.getModel(editorModel, this.editor);

if (!model) {
return false;
Expand Down Expand Up @@ -958,7 +958,7 @@ export class DirtyDiffController extends Disposable implements DirtyDiffContribu
return;
}

const model = this.modelRegistry.getModel(editorModel);
const model = this.modelRegistry.getModel(editorModel, this.editor);

if (!model) {
return;
Expand All @@ -985,7 +985,7 @@ export class DirtyDiffController extends Disposable implements DirtyDiffContribu
return [];
}

const model = this.modelRegistry.getModel(this.editor.getModel());
const model = this.modelRegistry.getModel(this.editor.getModel(), this.editor);

if (!model) {
return [];
Expand Down Expand Up @@ -1080,11 +1080,12 @@ class DirtyDiffDecorator extends Disposable {
private modifiedOptions: ModelDecorationOptions;
private modifiedPatternOptions: ModelDecorationOptions;
private deletedOptions: ModelDecorationOptions;
private decorations: string[] = [];
private decorationsCollection: IEditorDecorationsCollection | undefined;
private editorModel: ITextModel | null;

constructor(
editorModel: ITextModel,
private readonly codeEditor: ICodeEditor,
private model: DirtyDiffModel,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
Expand Down Expand Up @@ -1176,18 +1177,22 @@ class DirtyDiffDecorator extends Disposable {
}
});

this.decorations = this.editorModel.deltaDecorations(this.decorations, decorations);
if (!this.decorationsCollection) {
this.codeEditor.createDecorationsCollection(decorations);
} else {
this.decorationsCollection.set(decorations);
}
}

override dispose(): void {
super.dispose();

if (this.editorModel && !this.editorModel.isDisposed()) {
this.editorModel.deltaDecorations(this.decorations, []);
if (this.decorationsCollection) {
this.decorationsCollection?.clear();
}

this.editorModel = null;
this.decorations = [];
this.decorationsCollection = undefined;
}
}

Expand Down Expand Up @@ -1543,7 +1548,7 @@ export class DirtyDiffWorkbenchController extends Disposable implements ext.IWor

private enabled = false;
private viewState: IViewState = { width: 3, visibility: 'always' };
private items = new ResourceMap<DirtyDiffItem>();
private items = new ResourceMap<Map<string, DirtyDiffItem>>(); // resource -> editor id -> DirtyDiffItem
private readonly transientDisposables = this._register(new DisposableStore());
private stylesheet: HTMLStyleElement;

Expand Down Expand Up @@ -1636,7 +1641,7 @@ export class DirtyDiffWorkbenchController extends Disposable implements ext.IWor
this.transientDisposables.clear();

for (const [, dirtyDiff] of this.items) {
dirtyDiff.dispose();
dispose(dirtyDiff.values());
}

this.items.clear();
Expand All @@ -1653,28 +1658,31 @@ export class DirtyDiffWorkbenchController extends Disposable implements ext.IWor
controller.modelRegistry = this;
}

if (textModel && !this.items.has(textModel.uri)) {
if (textModel && (!this.items.has(textModel.uri) || !this.items.get(textModel.uri)!.has(editor.getId()))) {
const textFileModel = this.textFileService.files.get(textModel.uri);

if (textFileModel?.isResolved()) {
const dirtyDiffModel = this.instantiationService.createInstance(DirtyDiffModel, textFileModel);
const decorator = new DirtyDiffDecorator(textFileModel.textEditorModel, dirtyDiffModel, this.configurationService);
this.items.set(textModel.uri, new DirtyDiffItem(dirtyDiffModel, decorator));
const decorator = new DirtyDiffDecorator(textFileModel.textEditorModel, editor, dirtyDiffModel, this.configurationService);
if (!this.items.has(textModel.uri)) {
this.items.set(textModel.uri, new Map());
}
this.items.get(textModel.uri)?.set(editor.getId(), new DirtyDiffItem(dirtyDiffModel, decorator));
}
}
}
}

for (const [uri, item] of this.items) {
if (!this.editorService.isOpened({ resource: uri, typeId: FILE_EDITOR_INPUT_ID, editorId: DEFAULT_EDITOR_ASSOCIATION.id })) {
item.dispose();
dispose(item.values());
this.items.delete(uri);
}
}
}

getModel(editorModel: ITextModel): DirtyDiffModel | undefined {
return this.items.get(editorModel.uri)?.model;
getModel(editorModel: ITextModel, codeEditor: ICodeEditor): DirtyDiffModel | undefined {
return this.items.get(editorModel.uri)?.get(codeEditor.getId())?.model;
}

override dispose(): void {
Expand Down