mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Improve notebook editor height calculations (#3966)
* Improve notebook editor height calculations * PR comments, hook up to onDidChangeConfiguration
This commit is contained in:
@@ -25,6 +25,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
|
|||||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||||
import { Configuration } from 'vs/editor/browser/config/configuration';
|
import { Configuration } from 'vs/editor/browser/config/configuration';
|
||||||
|
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension of TextResourceEditor that is always readonly rather than only with non UntitledInputs
|
* Extension of TextResourceEditor that is always readonly rather than only with non UntitledInputs
|
||||||
@@ -36,16 +37,18 @@ export class QueryTextEditor extends BaseTextEditor {
|
|||||||
private _config: editorCommon.IConfiguration;
|
private _config: editorCommon.IConfiguration;
|
||||||
private _minHeight: number;
|
private _minHeight: number;
|
||||||
private _selected: boolean;
|
private _selected: boolean;
|
||||||
|
private _editorWorkspaceConfig;
|
||||||
|
private _scrollbarHeight: number;
|
||||||
constructor(
|
constructor(
|
||||||
@ITelemetryService telemetryService: ITelemetryService,
|
@ITelemetryService telemetryService: ITelemetryService,
|
||||||
@IInstantiationService instantiationService: IInstantiationService,
|
@IInstantiationService instantiationService: IInstantiationService,
|
||||||
@IStorageService storageService: IStorageService,
|
@IStorageService storageService: IStorageService,
|
||||||
@ITextResourceConfigurationService configurationService: ITextResourceConfigurationService,
|
@ITextResourceConfigurationService configurationService: ITextResourceConfigurationService,
|
||||||
@IThemeService themeService: IThemeService,
|
@IThemeService themeService: IThemeService,
|
||||||
@IModeService modeService: IModeService,
|
|
||||||
@ITextFileService textFileService: ITextFileService,
|
@ITextFileService textFileService: ITextFileService,
|
||||||
@IEditorGroupsService editorGroupService: IEditorGroupsService,
|
@IEditorGroupsService editorGroupService: IEditorGroupsService,
|
||||||
@IEditorService protected editorService: IEditorService,
|
@IEditorService protected editorService: IEditorService,
|
||||||
|
@IWorkspaceConfigurationService private workspaceConfigurationService: IWorkspaceConfigurationService
|
||||||
|
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
@@ -116,10 +119,11 @@ export class QueryTextEditor extends BaseTextEditor {
|
|||||||
return editorWidget.getScrollHeight();
|
return editorWidget.getScrollHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public setHeightToScrollHeight(): void {
|
public setHeightToScrollHeight(configChanged?: boolean): void {
|
||||||
let editorWidget = this.getControl() as ICodeEditor;
|
let editorWidget = this.getControl() as ICodeEditor;
|
||||||
if (!this._config) {
|
if (!this._config) {
|
||||||
this._config = new Configuration(undefined, editorWidget.getDomNode());
|
this._config = new Configuration(undefined, editorWidget.getDomNode());
|
||||||
|
this._scrollbarHeight = this._config.editor.viewInfo.scrollbar.horizontalScrollbarSize;
|
||||||
}
|
}
|
||||||
let editorWidgetModel = editorWidget.getModel();
|
let editorWidgetModel = editorWidget.getModel();
|
||||||
let lineCount = editorWidgetModel.getLineCount();
|
let lineCount = editorWidgetModel.getLineCount();
|
||||||
@@ -129,13 +133,30 @@ export class QueryTextEditor extends BaseTextEditor {
|
|||||||
// number of lines that wrap). Finally, viewportColumn is calculated on editor resizing automatically; we can use it to ensure
|
// number of lines that wrap). Finally, viewportColumn is calculated on editor resizing automatically; we can use it to ensure
|
||||||
// that the viewportColumn will always be greater than any character's column in an editor.
|
// that the viewportColumn will always be greater than any character's column in an editor.
|
||||||
let numberWrappedLines = 0;
|
let numberWrappedLines = 0;
|
||||||
|
let shouldAddHorizontalScrollbarHeight = false;
|
||||||
|
if (!this._editorWorkspaceConfig || configChanged) {
|
||||||
|
this._editorWorkspaceConfig = this.workspaceConfigurationService.getValue('editor');
|
||||||
|
}
|
||||||
|
let wordWrapEnabled: boolean = this._editorWorkspaceConfig && this._editorWorkspaceConfig['wordWrap'] && this._editorWorkspaceConfig['wordWrap'] === 'on' ? true : false;
|
||||||
|
if (wordWrapEnabled) {
|
||||||
for (let line = 1; line <= lineCount; line++) {
|
for (let line = 1; line <= lineCount; line++) {
|
||||||
if (editorWidgetModel.getLineMaxColumn(line) >= this._config.editor.layoutInfo.viewportColumn - 1) {
|
// 4 columns is equivalent to the viewport column width and the edge of the editor
|
||||||
|
if (editorWidgetModel.getLineMaxColumn(line) >= this._config.editor.layoutInfo.viewportColumn + 4) {
|
||||||
numberWrappedLines += Math.ceil(editorWidgetModel.getLineMaxColumn(line) / this._config.editor.layoutInfo.viewportColumn);
|
numberWrappedLines += Math.ceil(editorWidgetModel.getLineMaxColumn(line) / this._config.editor.layoutInfo.viewportColumn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for (let line = 1; line <= lineCount; line++) {
|
||||||
|
// The horizontal scrollbar always appears 1 column past the viewport column when word wrap is disabled
|
||||||
|
if (editorWidgetModel.getLineMaxColumn(line) >= this._config.editor.layoutInfo.viewportColumn + 1) {
|
||||||
|
shouldAddHorizontalScrollbarHeight = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
let editorHeightUsingLines = this._config.editor.lineHeight * (lineCount + numberWrappedLines);
|
let editorHeightUsingLines = this._config.editor.lineHeight * (lineCount + numberWrappedLines);
|
||||||
let editorHeightUsingMinHeight = Math.max(editorHeightUsingLines, this._minHeight);
|
let editorHeightUsingMinHeight = Math.max(editorHeightUsingLines, this._minHeight);
|
||||||
|
editorHeightUsingMinHeight = shouldAddHorizontalScrollbarHeight ? editorHeightUsingMinHeight + this._scrollbarHeight : editorHeightUsingMinHeight;
|
||||||
this.setHeight(editorHeightUsingMinHeight);
|
this.setHeight(editorHeightUsingMinHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import { IModeService } from 'vs/editor/common/services/modeService';
|
|||||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||||
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
|
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
|
||||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||||
|
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||||
|
|
||||||
export const CODE_SELECTOR: string = 'code-component';
|
export const CODE_SELECTOR: string = 'code-component';
|
||||||
|
|
||||||
@@ -83,6 +84,7 @@ export class CodeComponent extends AngularDisposable implements OnInit, OnChange
|
|||||||
@Inject(IContextMenuService) private contextMenuService: IContextMenuService,
|
@Inject(IContextMenuService) private contextMenuService: IContextMenuService,
|
||||||
@Inject(IContextViewService) private contextViewService: IContextViewService,
|
@Inject(IContextViewService) private contextViewService: IContextViewService,
|
||||||
@Inject(INotificationService) private notificationService: INotificationService,
|
@Inject(INotificationService) private notificationService: INotificationService,
|
||||||
|
@Inject(IConfigurationService) private _configurationService: IConfigurationService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this._cellToggleMoreActions = this._instantiationService.createInstance(CellToggleMoreActions);
|
this._cellToggleMoreActions = this._instantiationService.createInstance(CellToggleMoreActions);
|
||||||
@@ -149,6 +151,11 @@ export class CodeComponent extends AngularDisposable implements OnInit, OnChange
|
|||||||
this.cellModel.source = this._editorModel.getValue();
|
this.cellModel.source = this._editorModel.getValue();
|
||||||
this.onContentChanged.emit();
|
this.onContentChanged.emit();
|
||||||
}));
|
}));
|
||||||
|
this._register(this._configurationService.onDidChangeConfiguration(e => {
|
||||||
|
if (e.affectsConfiguration('editor.wordWrap')) {
|
||||||
|
this._editor.setHeightToScrollHeight(true);
|
||||||
|
}
|
||||||
|
}));
|
||||||
this._register(this.model.layoutChanged(this.layout, this));
|
this._register(this.model.layoutChanged(this.layout, this));
|
||||||
this.layout();
|
this.layout();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user