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

Added EventListener to Resize the DiffEditor #333

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions webClient/src/app/editor/code-editor/monaco/monaco.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class MonacoComponent implements OnInit, OnChanges {
private showEditor: boolean;
private showDiffViewer: boolean;
private keyBindingSub: Subscription = new Subscription();
private diffEditor: monaco.editor.IStandaloneDiffEditor | null ;

constructor(
private monacoService: MonacoService,
Expand All @@ -82,6 +83,11 @@ export class MonacoComponent implements OnInit, OnChanges {
this.monacoConfig = new MonacoConfig();
let options = this._options ? Object.assign({}, this._options) : {};
const hasModel = !!options.model;

this.viewportEvents.resized.subscribe(() => {
this.handleDiffEditorResize();
});


if (hasModel) {
const model = monaco.editor.getModel(options.model.uri || '');
Expand Down Expand Up @@ -115,10 +121,16 @@ export class MonacoComponent implements OnInit, OnChanges {
this.editorControl.enableDiffViewer.subscribe(() =>{
this.showEditor = !this.monacoService.spawnDiffViewer();
this.showDiffViewer = !this.showEditor;
if (this.showDiffViewer) {
this.diffEditor = this.monacoService.getDiffEditor();
}
});

this.editorControl.refreshLayout.subscribe(() =>{
setTimeout(() => this.editor.layout(), 1);
if (this.showDiffViewer) {
setTimeout(() => this.diffEditor.layout(), 1);
}
});

this.editor.onContextMenu((e: any) => {
Expand All @@ -137,6 +149,17 @@ export class MonacoComponent implements OnInit, OnChanges {
});
}

ngAfterViewInit() {
this.handleDiffEditorResize();
}


handleDiffEditorResize() {
if (this.showDiffViewer && this.diffEditor) {
setTimeout(() => this.diffEditor.layout(), 1);
}
}

focus(e: any) {
this.editor.focus();
}
Expand All @@ -157,6 +180,7 @@ export class MonacoComponent implements OnInit, OnChanges {
}
this.showEditor = true;
this.showDiffViewer = false;
this.diffEditor = null;
}
}
}
Expand Down Expand Up @@ -386,10 +410,14 @@ export class MonacoComponent implements OnInit, OnChanges {
if (this.showDiffViewer) {
this.showDiffViewer = false;
this.showEditor = true;
this.diffEditor.dispose();
}
else {
this.showEditor = !this.monacoService.spawnDiffViewer();
this.showDiffViewer = !this.showEditor;
if (this.showDiffViewer) {
this.diffEditor = this.monacoService.getDiffEditor();
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions webClient/src/app/editor/code-editor/monaco/monaco.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ export class MonacoService implements OnDestroy {
return true;
}

getDiffEditor(): monaco.editor.IStandaloneDiffEditor {
return this.diffEditor;
}

closeFile(fileNode: ProjectContext) {
const editorCore = this.editorControl.editorCore.getValue();
if (!editorCore) {
Expand Down