Skip to content

Commit d939e5d

Browse files
authored
Merge pull request microsoft#183522 from microsoft/hediet/changes
Bugfixes
2 parents 4661aa6 + 0176566 commit d939e5d

File tree

9 files changed

+93
-34
lines changed

9 files changed

+93
-34
lines changed

src/vs/base/common/observableImpl/autorun.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,41 @@ export function autorunHandleChanges<TChangeSummary>(
2323
return new AutorunObserver(debugName, fn, options.createEmptyChangeSummary, options.handleChange);
2424
}
2525

26+
// TODO@hediet rename to autorunWithStore
27+
export function autorunWithStore2(
28+
debugName: string,
29+
fn: (reader: IReader, store: DisposableStore) => void,
30+
): IDisposable {
31+
return autorunWithStore(fn, debugName);
32+
}
33+
34+
export function autorunWithStoreHandleChanges<TChangeSummary>(
35+
debugName: string,
36+
options: {
37+
createEmptyChangeSummary?: () => TChangeSummary;
38+
handleChange: (context: IChangeContext, changeSummary: TChangeSummary) => boolean;
39+
},
40+
fn: (reader: IReader, changeSummary: TChangeSummary, store: DisposableStore) => void
41+
): IDisposable {
42+
const store = new DisposableStore();
43+
const disposable = autorunHandleChanges(
44+
debugName,
45+
{
46+
createEmptyChangeSummary: options.createEmptyChangeSummary,
47+
handleChange: options.handleChange,
48+
},
49+
(reader, changeSummary) => {
50+
store.clear();
51+
fn(reader, changeSummary, store);
52+
}
53+
);
54+
return toDisposable(() => {
55+
disposable.dispose();
56+
store.dispose();
57+
});
58+
}
59+
60+
// TODO@hediet deprecate, rename to autorunWithStoreEx
2661
export function autorunWithStore(
2762
fn: (reader: IReader, store: DisposableStore) => void,
2863
debugName: string
@@ -144,13 +179,13 @@ export class AutorunObserver<TChangeSummary = any> implements IObserver, IReader
144179
}
145180

146181
public handlePossibleChange(observable: IObservable<any>): void {
147-
if (this.state === AutorunState.upToDate && this.dependencies.has(observable)) {
182+
if (this.state === AutorunState.upToDate && this.dependencies.has(observable) && !this.dependenciesToBeRemoved.has(observable)) {
148183
this.state = AutorunState.dependenciesMightHaveChanged;
149184
}
150185
}
151186

152187
public handleChange<T, TChange>(observable: IObservable<T, TChange>, change: TChange): void {
153-
if (this.dependencies.has(observable)) {
188+
if (this.dependencies.has(observable) && !this.dependenciesToBeRemoved.has(observable)) {
154189
const shouldReact = this._handleChange ? this._handleChange({
155190
changedObservable: observable,
156191
change,

src/vs/base/common/observableImpl/base.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import { IDisposable } from 'vs/base/common/lifecycle';
77
import type { derived } from 'vs/base/common/observableImpl/derived';
88
import { getLogger } from 'vs/base/common/observableImpl/logging';
99

10+
/**
11+
* Represents an observable value.
12+
* @template T The type of the value.
13+
* @template TChange The type of delta information (usually `void` and only used in advanced scenarios).
14+
*/
1015
export interface IObservable<T, TChange = unknown> {
1116
/**
1217
* Returns the current value.
@@ -248,6 +253,10 @@ export function getFunctionName(fn: Function): string | undefined {
248253
export interface ISettableObservable<T, TChange = void> extends IObservable<T, TChange>, ISettable<T, TChange> {
249254
}
250255

256+
/**
257+
* Creates an observable value.
258+
* Observers get informed when the value changes.
259+
*/
251260
export function observableValue<T, TChange = void>(name: string, initialValue: T): ISettableObservable<T, TChange> {
252261
return new ObservableValue(name, initialValue);
253262
}

src/vs/base/common/observableImpl/derived.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class Derived<T, TChangeSummary = any> extends BaseObservable<T, void> im
196196

197197
public handlePossibleChange<T>(observable: IObservable<T, unknown>): void {
198198
// In all other states, observers already know that we might have changed.
199-
if (this.state === DerivedState.upToDate && this.dependencies.has(observable)) {
199+
if (this.state === DerivedState.upToDate && this.dependencies.has(observable) && !this.dependenciesToBeRemoved.has(observable)) {
200200
this.state = DerivedState.dependenciesMightHaveChanged;
201201
for (const r of this.observers) {
202202
r.handlePossibleChange(this);
@@ -205,22 +205,19 @@ export class Derived<T, TChangeSummary = any> extends BaseObservable<T, void> im
205205
}
206206

207207
public handleChange<T, TChange>(observable: IObservable<T, TChange>, change: TChange): void {
208-
const isUpToDate = this.state === DerivedState.upToDate;
209-
let shouldReact = true;
210-
211-
if (this._handleChange && this.dependencies.has(observable)) {
212-
shouldReact = this._handleChange({
208+
if (this.dependencies.has(observable) && !this.dependenciesToBeRemoved.has(observable)) {
209+
const shouldReact = this._handleChange ? this._handleChange({
213210
changedObservable: observable,
214211
change,
215212
didChange: o => o === observable as any,
216-
}, this.changeSummary!);
217-
}
218-
219-
if (shouldReact && (this.state === DerivedState.dependenciesMightHaveChanged || isUpToDate) && this.dependencies.has(observable)) {
220-
this.state = DerivedState.stale;
221-
if (isUpToDate) {
222-
for (const r of this.observers) {
223-
r.handlePossibleChange(this);
213+
}, this.changeSummary!) : true;
214+
const wasUpToDate = this.state === DerivedState.upToDate;
215+
if (shouldReact && (this.state === DerivedState.dependenciesMightHaveChanged || wasUpToDate)) {
216+
this.state = DerivedState.stale;
217+
if (wasUpToDate) {
218+
for (const r of this.observers) {
219+
r.handlePossibleChange(this);
220+
}
224221
}
225222
}
226223
}

src/vs/base/common/observableImpl/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ class FromEventObservableSignal extends BaseObservable<void> {
198198
}
199199
}
200200

201+
/**
202+
* Creates a signal that can be triggered to invalidate observers.
203+
*/
201204
export function observableSignal<TDelta = void>(
202205
debugName: string
203206
): IObservableSignal<TDelta> {
@@ -287,6 +290,10 @@ export function wasEventTriggeredRecently(event: Event<any>, timeoutMs: number,
287290
export function keepAlive(observable: IObservable<any>, forceRecompute?: boolean): IDisposable {
288291
const o = new KeepAliveObserver(forceRecompute ?? false);
289292
observable.addObserver(o);
293+
if (forceRecompute) {
294+
observable.reportChanges();
295+
}
296+
290297
return toDisposable(() => {
291298
observable.removeObserver(o);
292299
});

src/vs/editor/browser/editorBrowser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { IEditorWhitespace, IViewModel } from 'vs/editor/common/viewModel';
2121
import { InjectedText } from 'vs/editor/common/modelLineProjectionData';
2222
import { ILineChange, IDiffComputationResult } from 'vs/editor/common/diff/smartLinesDiffComputer';
2323
import { IDimension } from 'vs/editor/common/core/dimension';
24+
import { IBoundarySashes } from 'vs/base/browser/ui/sash/sash';
2425

2526
/**
2627
* A view zone is a full horizontal rectangle that 'pushes' text down.
@@ -1210,6 +1211,11 @@ export interface IDiffEditor extends editorCommon.IEditor {
12101211
* Update the editor's options after the editor has been created.
12111212
*/
12121213
updateOptions(newOptions: IDiffEditorOptions): void;
1214+
1215+
/**
1216+
* @internal
1217+
*/
1218+
setBoundarySashes(sashes: IBoundarySashes): void;
12131219
}
12141220

12151221
/**

src/vs/editor/browser/widget/diffEditorWidget.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
866866
return this._domElement;
867867
}
868868

869+
// #region editorBrowser.IDiffEditor: Delegating to modified Editor
870+
869871
public getVisibleColumnFromPosition(position: IPosition): number {
870872
return this._modifiedEditor.getVisibleColumnFromPosition(position);
871873
}
@@ -978,6 +980,24 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
978980
return this._modifiedEditor.getSupportedActions();
979981
}
980982

983+
public focus(): void {
984+
this._modifiedEditor.focus();
985+
}
986+
987+
public trigger(source: string | null | undefined, handlerId: string, payload: any): void {
988+
this._modifiedEditor.trigger(source, handlerId, payload);
989+
}
990+
991+
public createDecorationsCollection(decorations?: IModelDeltaDecoration[]): editorCommon.IEditorDecorationsCollection {
992+
return this._modifiedEditor.createDecorationsCollection(decorations);
993+
}
994+
995+
public changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any {
996+
return this._modifiedEditor.changeDecorations(callback);
997+
}
998+
999+
// #endregion
1000+
9811001
public saveViewState(): editorCommon.IDiffEditorViewState {
9821002
const originalViewState = this._originalEditor.saveViewState();
9831003
const modifiedViewState = this._modifiedEditor.saveViewState();
@@ -999,9 +1019,6 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
9991019
this._elementSizeObserver.observe(dimension);
10001020
}
10011021

1002-
public focus(): void {
1003-
this._modifiedEditor.focus();
1004-
}
10051022

10061023
public hasTextFocus(): boolean {
10071024
return this._originalEditor.hasTextFocus() || this._modifiedEditor.hasTextFocus();
@@ -1023,18 +1040,6 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
10231040
this._cleanViewZonesAndDecorations();
10241041
}
10251042

1026-
public trigger(source: string | null | undefined, handlerId: string, payload: any): void {
1027-
this._modifiedEditor.trigger(source, handlerId, payload);
1028-
}
1029-
1030-
public createDecorationsCollection(decorations?: IModelDeltaDecoration[]): editorCommon.IEditorDecorationsCollection {
1031-
return this._modifiedEditor.createDecorationsCollection(decorations);
1032-
}
1033-
1034-
public changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any {
1035-
return this._modifiedEditor.changeDecorations(callback);
1036-
}
1037-
10381043
//------------ end IDiffEditor methods
10391044

10401045

src/vs/editor/common/diff/documentDiffProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface IDocumentDiffProvider {
2828
*/
2929
export interface IDocumentDiffProviderOptions {
3030
/**
31-
* When set to true, the diff should ignore whitespace changes.i
31+
* When set to true, the diff should ignore whitespace changes.
3232
*/
3333
ignoreTrimWhitespace: boolean;
3434

src/vs/monaco.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2348,7 +2348,7 @@ declare namespace monaco.editor {
23482348
*/
23492349
export interface IDocumentDiffProviderOptions {
23502350
/**
2351-
* When set to true, the diff should ignore whitespace changes.i
2351+
* When set to true, the diff should ignore whitespace changes.
23522352
*/
23532353
ignoreTrimWhitespace: boolean;
23542354
/**

src/vs/workbench/browser/parts/editor/textDiffEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class TextDiffEditor extends AbstractTextEditor<IDiffEditorViewState> imp
4545

4646
static readonly ID = TEXT_DIFF_EDITOR_ID;
4747

48-
private diffEditorControl: DiffEditorWidget | undefined = undefined;
48+
private diffEditorControl: IDiffEditor | undefined = undefined;
4949

5050
private diffNavigator: DiffNavigator | undefined;
5151
private readonly diffNavigatorDisposables = this._register(new DisposableStore());

0 commit comments

Comments
 (0)