Skip to content

Commit

Permalink
address CG feedback and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kenneth-marut-work committed Jun 1, 2021
1 parent 7473220 commit e31d44e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
32 changes: 18 additions & 14 deletions packages/debug/src/browser/editor/debug-breakpoint-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ export class DebugBreakpointWidget implements Disposable {

protected readonly toDispose = new DisposableCollection();

protected expressionInput: MonacoEditor;
set expressionInputSize(dimension: Dimension | undefined) {
if (this.expressionInput && dimension) {
this.expressionInput.setSize(dimension);
}
}

protected context: DebugBreakpointWidget.Context = 'condition';
protected _values: {
[context in DebugBreakpointWidget.Context]?: string
Expand All @@ -77,6 +70,16 @@ export class DebugBreakpointWidget implements Disposable {
get input(): MonacoEditor | undefined {
return this._input;
}
// eslint-disable-next-line no-null/no-null
set inputSize(dimension: Dimension | null) {
if (this._input) {
if (dimension) {
this._input.setSize(dimension);
} else {
this._input.resizeToFit();
}
}
}

@postConstruct()
protected async init(): Promise<void> {
Expand All @@ -90,17 +93,18 @@ export class DebugBreakpointWidget implements Disposable {
const inputNode = document.createElement('div');
inputNode.classList.add('theia-debug-breakpoint-input');
this.zone.containerNode.appendChild(inputNode);
this.expressionInput = this._input = await this.createInput(inputNode);

const input = this._input = await this.createInput(inputNode);
if (this.toDispose.disposed) {
this.expressionInput.dispose();
input.dispose();
return;
}
this.toDispose.push(this.expressionInput);
this.toDispose.push(monaco.modes.CompletionProviderRegistry.register({ scheme: this.expressionInput.uri.scheme }, {
this.toDispose.push(input);
this.toDispose.push(monaco.modes.CompletionProviderRegistry.register({ scheme: input.uri.scheme }, {
provideCompletionItems: async (model, position, context, token) => {
const suggestions = [];
if ((this.context === 'condition' || this.context === 'logMessage')
&& this.expressionInput.uri.toString() === model.uri.toString()) {
&& input.uri.toString() === model.uri.toString()) {
const editor = this.editor.getControl();
const items = await monaco.suggest.provideSuggestionItems(
editor.getModel()!,
Expand All @@ -127,8 +131,8 @@ export class DebugBreakpointWidget implements Disposable {
}
}));
this.toDispose.push(this.zone.onDidLayoutChange(dimension => this.layout(dimension)));
this.toDispose.push(this.expressionInput.getControl().onDidChangeModelContent(() => {
const heightInLines = this.expressionInput.getControl().getModel()!.getLineCount() + 1;
this.toDispose.push(input.getControl().onDidChangeModelContent(() => {
const heightInLines = input.getControl().getModel()!.getLineCount() + 1;
this.zone.layout(heightInLines);
this.updatePlaceholder();
}));
Expand Down
2 changes: 1 addition & 1 deletion packages/debug/src/browser/editor/debug-editor-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class DebugEditorModel implements Disposable {
this.editor.getControl().onKeyDown(() => this.hover.hide({ immediate: false })),
this.editor.getControl().onDidChangeModelContent(() => this.update()),
this.editor.getControl().getModel()!.onDidChangeDecorations(() => this.updateBreakpoints()),
this.editor.onResized(e => this.breakpointWidget.expressionInputSize = e),
this.editor.onResized(e => this.breakpointWidget.inputSize = e),
this.sessions.onDidChange(() => this.update()),
this.toDisposeOnUpdate
]);
Expand Down
6 changes: 4 additions & 2 deletions packages/monaco/src/browser/monaco-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export class MonacoEditor extends MonacoEditorServices implements TextEditor {
readonly onLanguageChanged = this.onLanguageChangedEmitter.event;
protected readonly onScrollChangedEmitter = new Emitter<void>();
readonly onEncodingChanged = this.document.onDidChangeEncoding;
protected readonly onResizeEmitter = new Emitter<Dimension | undefined>();
// eslint-disable-next-line no-null/no-null
protected readonly onResizeEmitter = new Emitter<Dimension | null>();
readonly onResized = this.onResizeEmitter.event;

readonly documents = new Set<MonacoEditorModel>();
Expand Down Expand Up @@ -342,6 +343,8 @@ export class MonacoEditor extends MonacoEditorServices implements TextEditor {

resizeToFit(): void {
this.autoresize();
// eslint-disable-next-line no-null/no-null
this.onResizeEmitter.fire(null);
}

setSize(dimension: Dimension): void {
Expand All @@ -360,7 +363,6 @@ export class MonacoEditor extends MonacoEditorServices implements TextEditor {
if (this.node) {
const layoutSize = this.computeLayoutSize(this.node, dimension);
this.editor.layout(layoutSize);
this.onResizeEmitter.fire(undefined);
}
}

Expand Down

0 comments on commit e31d44e

Please sign in to comment.