Skip to content

Commit

Permalink
feat: support activeEditorIsDirty contextKey
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaaaash committed Dec 26, 2024
1 parent 1a08936 commit 9b727d3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/editor/src/browser/workbench-editor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {

private _editorLangIDContextKey: IContextKey<string>;

private _activeEditorIsDirtyContextKey: IContextKey<boolean>;

private _isInDiffEditorContextKey: IContextKey<boolean>;

private _diffResourceContextKey: ResourceContextKey;
Expand Down Expand Up @@ -905,6 +907,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
);
this._editorLangIDContextKey = this.contextKeyService.createKey<string>('editorLangId', '');
this._isInDiffEditorContextKey = this.contextKeyService.createKey<boolean>('isInDiffEditor', false);
this._activeEditorIsDirtyContextKey = this.contextKeyService.createKey<boolean>('activeEditorIsDirty', false);
this._isInDiffRightEditorContextKey = this.contextKeyService.createKey<boolean>('isInDiffRightEditor', false);
this._isInEditorComponentContextKey = this.contextKeyService.createKey<boolean>('inEditorComponent', false);
}
Expand All @@ -926,6 +929,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
}
this._editorLangIDContextKey.reset();
}
this._activeEditorIsDirtyContextKey.set(this.activeEditorIsDirty());
this._isInDiffEditorContextKey.set(this.isDiffEditorMode());
// 没有 focus 的时候默认添加在 RightDiffEditor
this._isInDiffRightEditorContextKey.set(this.isDiffEditorMode());
Expand Down Expand Up @@ -1176,6 +1180,12 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
editorId: this.codeEditor.getId(),
}),
);

this.toDispose.push(
this.codeEditor.monacoEditor.onDidChangeModelContent(() => {
this._activeEditorIsDirtyContextKey.set(this.activeEditorIsDirty());
}),
);
this.codeEditorReady.ready();
}

Expand Down Expand Up @@ -2239,6 +2249,10 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
return !!this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff;
}

activeEditorIsDirty() {
return this.hasDirty() && this.workbenchEditorService.currentEditorGroup === this;
}

isComponentMode() {
return !!this.currentOpenType && this.currentOpenType.type === EditorOpenType.component;
}
Expand Down

0 comments on commit 9b727d3

Please sign in to comment.