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

Setting interactive editor dynamic height #184330

Merged
merged 2 commits into from
Jun 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion build/lib/stylelint/vscode-known-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,8 @@
"--vscode-editorCodeLens-fontSize",
"--vscode-editorCodeLens-lineHeight",
"--vscode-explorer-align-offset-margin-left",
"--vscode-interactive-editor-cropped",
"--vscode-interactive-editor-expanded",
"--vscode-interactive-session-foreground",
"--vscode-interactive-result-editor-background-color",
"--vscode-repl-font-family",
Expand Down Expand Up @@ -741,4 +743,4 @@
"--z-index-run-button-container",
"--zoom-factor"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,22 @@

.monaco-editor .interactive-editor .markdownMessage .message {
margin-left: 5px;
-webkit-line-clamp: 3;
-webkit-line-clamp: initial;
-webkit-box-orient: vertical;
overflow: hidden;
display: -webkit-box;
-webkit-user-select: text;
user-select: text;
}

.monaco-editor .interactive-editor .markdownMessage .message[state="cropped"] {
-webkit-line-clamp: var(--vscode-interactive-editor-cropped, 3);
}

.monaco-editor .interactive-editor .markdownMessage .message[state="expanded"] {
-webkit-line-clamp: var(--vscode-interactive-editor-expanded, 10);
}

.monaco-editor .interactive-editor .markdownMessage .messageActions {
direction: rtl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ export interface InteractiveEditorWidgetViewState {
placeholder: string;
}

const MESSAGE_CROPPED_NUMBER_LINES = 3;
const MESSAGE_EXPANDED_NUMBER_LINES = 10;

export class InteractiveEditorWidget {

private static _modelPool: number = 1;
Expand Down Expand Up @@ -188,7 +185,7 @@ export class InteractiveEditorWidget {
private _expansionState: ExpansionState = ExpansionState.NOT_CROPPED;

constructor(
parentEditor: ICodeEditor,
private readonly parentEditor: ICodeEditor,
@IModelService private readonly _modelService: IModelService,
@ILanguageService private readonly _languageService: ILanguageService,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
Expand All @@ -208,7 +205,7 @@ export class InteractiveEditorWidget {
])
};

this._inputEditor = <IActiveCodeEditor>this._instantiationService.createInstance(EmbeddedCodeEditorWidget, this._elements.editor, _inputEditorOptions, codeEditorWidgetOptions, parentEditor);
this._inputEditor = <IActiveCodeEditor>this._instantiationService.createInstance(EmbeddedCodeEditorWidget, this._elements.editor, _inputEditorOptions, codeEditorWidgetOptions, this.parentEditor);
this._updateAriaLabel();
this._store.add(this._inputEditor);
this._store.add(this._inputEditor.onDidChangeModelContent(() => this._onDidChangeInput.fire(this)));
Expand Down Expand Up @@ -397,6 +394,12 @@ export class InteractiveEditorWidget {
const previewCreateDim = new Dimension(dim.width, Math.min(300, Math.max(0, this._previewCreateEditor.value.getContentHeight())));
this._previewCreateEditor.value.layout(previewCreateDim);
this._elements.previewCreate.style.height = `${previewCreateDim.height}px`;

const lineHeight = this.parentEditor.getOption(EditorOption.lineHeight);
const editorHeight = this.parentEditor.getLayoutInfo().height;
const editorHeightInLines = Math.floor(editorHeight / lineHeight);
this._elements.root.style.setProperty('--vscode-interactive-editor-cropped', String(Math.floor(editorHeightInLines / 5)));
this._elements.root.style.setProperty('--vscode-interactive-editor-expanded', String(Math.floor(editorHeightInLines / 3)));
}
} finally {
this._isLayouting = false;
Expand Down Expand Up @@ -475,25 +478,30 @@ export class InteractiveEditorWidget {
expansionState = this._preferredExpansionState;
this._preferredExpansionState = undefined;
} else {
this._elements.message.style.webkitLineClamp = MESSAGE_CROPPED_NUMBER_LINES.toString();
this._updateLineClamp(ExpansionState.CROPPED);
reset(this._elements.message, message);
expansionState = this._elements.message.scrollHeight > this._elements.message.clientHeight ? ExpansionState.CROPPED : ExpansionState.NOT_CROPPED;
}
this._ctxMessageCropState.set(expansionState);
this.updateLineClamp(expansionState);
this._updateLineClamp(expansionState);
}
this._expansionState = expansionState;
this._onDidChangeHeight.fire();
}

updateMarkdownMessageExpansionState(expansionState: ExpansionState) {
this._ctxMessageCropState.set(expansionState);
this.updateLineClamp(expansionState);
const heightBefore = this._elements.markdownMessage.scrollHeight;
this._updateLineClamp(expansionState);
const heightAfter = this._elements.markdownMessage.scrollHeight;
if (heightBefore === heightAfter) {
this._ctxMessageCropState.set(ExpansionState.NOT_CROPPED);
}
this._onDidChangeHeight.fire();
}

updateLineClamp(expansionState: ExpansionState) {
this._elements.message.style.webkitLineClamp = expansionState === ExpansionState.NOT_CROPPED ? 'none' : (expansionState === ExpansionState.EXPANDED ? MESSAGE_EXPANDED_NUMBER_LINES.toString() : MESSAGE_CROPPED_NUMBER_LINES.toString());
private _updateLineClamp(expansionState: ExpansionState) {
this._elements.message.setAttribute('state', expansionState);
}

updateInfo(message: string): void {
Expand Down