这是indexloc提供的服务,不要输入任何密码
Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/microsoft-trydotnet-editor/src/EditorAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export abstract class EditorAdapter {
abstract setPosition(position: { line: number, column: number }): void;
abstract updateOptions(options: any): void;
abstract focus(): void;
abstract layout(size: { width: number, height: number }): void;


private _diagnostics: polyglotNotebooks.Diagnostic[] = [];
abstract setMarkers(markers: IMarkerData[]);
Expand Down
4 changes: 4 additions & 0 deletions src/microsoft-trydotnet-editor/src/monacoAdapterImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export class MonacoEditorAdapter extends editorAdapter.EditorAdapter {
this._editor.focus();
}

layout(size: { width: number, height: number }): void {
this._editor.layout(size);
}

private _onDidChangeModelContentEvents: rxjs.Subject<monaco.editor.IModelContentChangedEvent> = new rxjs.Subject<monaco.editor.IModelContentChangedEvent>();

constructor(private _editor: monaco.editor.IStandaloneCodeEditor) {
Expand Down
9 changes: 9 additions & 0 deletions src/microsoft-trydotnet-editor/src/newContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as polyglotNotebooks from '@microsoft/polyglot-notebooks';
export const EditorContentChangedType = "EditorContentChanged";
export const ConfigureMonacoEditorType = "ConfigureMonacoEditor";
export const SetMonacoEditorSizeType = "SetMonacoEditorSize";
export const DefineMonacoEditorThemesType = "DefineMonacoEditorThemes";
export const SetEditorContentType = "SetEditorContent";
export const EnableLoggingType = "EnableLogging";
Expand Down Expand Up @@ -50,6 +51,14 @@ export interface OpenDocument {
requestId: string;
}

export interface SetMonacoEditorSize {
type: typeof SetMonacoEditorSizeType;
size: {
width: number,
height: number
}
}

export interface CongureMonacoEditor {
type: typeof ConfigureMonacoEditorType;
editorOptions?: any,
Expand Down
4 changes: 4 additions & 0 deletions src/microsoft-trydotnet-editor/src/tryDotNetEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ export class TryDotNetEditor {
case newContract.EnableLoggingType:
configureLogging({ enableLogging: apiMessage.enableLogging });
break;
case newContract.SetMonacoEditorSizeType:
let size = (<newContract.SetMonacoEditorSize>apiMessage).size;
this.getEditor().layout(size);
break;
case newContract.ConfigureMonacoEditorType:
let options = {};
if (apiMessage.editorOptions) {
Expand Down
6 changes: 6 additions & 0 deletions src/microsoft-trydotnet-editor/tests/monacoEditorSimulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as editorAdapter from "../src/EditorAdapter";

export class MonacoEditorSimulator extends editorAdapter.EditorAdapter {

private _language: string;
private _themes: { [x: string]: any; } = {};
private _position: {
Expand All @@ -13,9 +14,14 @@ export class MonacoEditorSimulator extends editorAdapter.EditorAdapter {

private _options = {};
private _code: string;
private _size?: { width: number; height: number; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be optional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only internal state of test object, can be udnefined


private _markers: editorAdapter.IMarkerData[];

layout(size: { width: number; height: number; } | undefined): void {
this._size = size;
}

setMarkers(markers: editorAdapter.IMarkerData[]) {
this._markers = markers;
}
Expand Down
1 change: 1 addition & 0 deletions src/microsoft-trydotnet/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ export interface IMonacoEditor extends ITextEditor {
setTheme(theme: Theme): void;
setOptions(options: MonacoEditorOptions): void;
configure(configuration: MonacoEditorConfiguration): void;
setSize(size: { width: number, height: number }): void;
}
9 changes: 9 additions & 0 deletions src/microsoft-trydotnet/src/internals/monacoTextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ export class MonacoTextEditor implements ITrydotnetMonacoTextEditor {
this.editorApimessageBus.post(request);
}

public setSize(size: { width: number, height: number }): void {
const request: newContract.SetMonacoEditorSize = {
type: newContract.SetMonacoEditorSizeType,
size: size
};

this.editorApimessageBus.post(request);
}

public configure(configuration: MonacoEditorConfiguration): void {
this.setOptions(configuration.options);
this.setTheme(configuration.theme);
Expand Down
9 changes: 9 additions & 0 deletions src/microsoft-trydotnet/src/newContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as polyglotNotebooks from '@microsoft/polyglot-notebooks';
export const EditorContentChangedType = "EditorContentChanged";
export const ConfigureMonacoEditorType = "ConfigureMonacoEditor";
export const SetMonacoEditorSizeType = "SetMonacoEditorSize";
export const DefineMonacoEditorThemesType = "DefineMonacoEditorThemes";
export const SetEditorContentType = "SetEditorContent";
export const EnableLoggingType = "EnableLogging";
Expand Down Expand Up @@ -50,6 +51,14 @@ export interface OpenDocument {
requestId: string;
}

export interface SetMonacoEditorSize {
type: typeof SetMonacoEditorSizeType;
size: {
width: number,
height: number
}
}

export interface CongureMonacoEditor {
type: typeof ConfigureMonacoEditorType;
editorOptions?: any,
Expand Down
20 changes: 20 additions & 0 deletions src/microsoft-trydotnet/src/sessionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { configureEmbeddableEditorIFrame, configureEmbeddableEditorIFrameWithPac
import { Project } from "./project";
import { Logger } from "@microsoft/polyglot-notebooks";
import { configureLogging } from "./log";
import { IMonacoEditor } from "./editor";

async function _createSession(configuration: Configuration, editorIFrame: HTMLIFrameElement, window: Window, initialState: InitialSessionState, configureEmbeddableEditorIFrameCallBack: (editorIFrame: HTMLIFrameElement, configuration: Configuration) => void): Promise<ISession> {

Expand All @@ -18,6 +19,25 @@ async function _createSession(configuration: Configuration, editorIFrame: HTMLIF
let messageBus = new IFrameMessageBus(editorIFrame, window);
let session = new Session(messageBus);

// listen for size and visibility changes
try {
const resizeObserver = new ResizeObserver((entries, _observer) => {
for (const entry of entries) {
const { width, height } = entry.contentRect;
let editor = <IMonacoEditor>(session.getTextEditor());
editor.setSize({ width, height });
}
});

resizeObserver.observe(editorIFrame);
} catch (e) {
Logger.default.error("Error creating ResizeObserver");
}

editorIFrame.addEventListener("load", () => {
configureEmbeddableEditorIFrameCallBack(editorIFrame, configuration);
});

let src = editorIFrame.getAttribute("src");
if (!src) {
configureEmbeddableEditorIFrameCallBack(messageBus.targetIframe(), configuration);
Expand Down
3 changes: 3 additions & 0 deletions src/microsoft-trydotnet/test/fakes/fakeMonacoTextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export class FakeMonacoTextEditor implements ITrydotnetMonacoTextEditor {
this.editorId = "0";
}
}
setSize(size: { width: number; height: number; }): void {

}

public id(): string {
return this.editorId;
Expand Down