From 99f6d9b8e288820db79b3a7f08cc25d801a4b646 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 11 Feb 2016 12:16:28 +0100 Subject: [PATCH] Small perf tweaks --- src/vs/editor/common/commonCodeEditor.ts | 9 +- .../common/config/commonEditorConfig.ts | 104 ++++++++++++++++++ src/vs/editor/common/model/model.ts | 1 + .../browser/parts/editor/editorStatus.ts | 41 +++++-- 4 files changed, 144 insertions(+), 11 deletions(-) diff --git a/src/vs/editor/common/commonCodeEditor.ts b/src/vs/editor/common/commonCodeEditor.ts index a69be44199f..b77d11a86d7 100644 --- a/src/vs/editor/common/commonCodeEditor.ts +++ b/src/vs/editor/common/commonCodeEditor.ts @@ -198,7 +198,7 @@ export abstract class CommonCodeEditor extends EventEmitter.EventEmitter impleme } public getConfiguration(): EditorCommon.IInternalEditorOptions { - return Objects.clone(this._configuration.editor); + return this._configuration.editorClone; } public getRawConfiguration(): EditorCommon.IEditorOptions { @@ -206,7 +206,11 @@ export abstract class CommonCodeEditor extends EventEmitter.EventEmitter impleme } public getIndentationOptions(): EditorCommon.IInternalIndentationOptions { - return Objects.clone(this._configuration.getIndentationOptions()); + let r = this._configuration.getIndentationOptions(); + return { + tabSize: r.tabSize, + insertSpaces: r.insertSpaces + }; } public normalizeIndentation(str:string): string { @@ -643,6 +647,7 @@ export abstract class CommonCodeEditor extends EventEmitter.EventEmitter impleme this._decorationTypeKeysToIds[decorationTypeKey] = this.deltaDecorations(oldDecorationIds, ranges.map((r) : EditorCommon.IModelDeltaDecoration => { let decOpts: EditorCommon.IModelDecorationOptions; if (r.hoverMessage) { + // TODO@Alex: avoid Objects.clone decOpts = Objects.clone(opts); decOpts.htmlMessage = r.hoverMessage; } else { diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index 7a5d78a6fd2..0ac5e627141 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -62,6 +62,107 @@ export class ConfigurationWithDefaults { } } +function cloneInternalEditorOptions(opts: EditorCommon.IInternalEditorOptions): EditorCommon.IInternalEditorOptions { + return { + experimentalScreenReader: opts.experimentalScreenReader, + rulers: opts.rulers.slice(0), + ariaLabel: opts.ariaLabel, + lineNumbers: opts.lineNumbers, + selectOnLineNumbers: opts.selectOnLineNumbers, + glyphMargin: opts.glyphMargin, + revealHorizontalRightPadding: opts.revealHorizontalRightPadding, + roundedSelection: opts.roundedSelection, + theme: opts.theme, + readOnly: opts.readOnly, + scrollbar: { + arrowSize: opts.scrollbar.arrowSize, + vertical: opts.scrollbar.vertical, + horizontal: opts.scrollbar.horizontal, + useShadows: opts.scrollbar.useShadows, + verticalHasArrows: opts.scrollbar.verticalHasArrows, + horizontalHasArrows: opts.scrollbar.horizontalHasArrows, + handleMouseWheel: opts.scrollbar.handleMouseWheel, + horizontalScrollbarSize: opts.scrollbar.horizontalScrollbarSize, + horizontalSliderSize: opts.scrollbar.horizontalSliderSize, + verticalScrollbarSize: opts.scrollbar.verticalScrollbarSize, + verticalSliderSize: opts.scrollbar.verticalSliderSize, + mouseWheelScrollSensitivity: opts.scrollbar.mouseWheelScrollSensitivity, + }, + overviewRulerLanes: opts.overviewRulerLanes, + cursorBlinking: opts.cursorBlinking, + cursorStyle: opts.cursorStyle, + fontLigatures: opts.fontLigatures, + hideCursorInOverviewRuler: opts.hideCursorInOverviewRuler, + scrollBeyondLastLine: opts.scrollBeyondLastLine, + wrappingIndent: opts.wrappingIndent, + wordWrapBreakBeforeCharacters: opts.wordWrapBreakBeforeCharacters, + wordWrapBreakAfterCharacters: opts.wordWrapBreakAfterCharacters, + wordWrapBreakObtrusiveCharacters: opts.wordWrapBreakObtrusiveCharacters, + tabFocusMode: opts.tabFocusMode, + stopLineTokenizationAfter: opts.stopLineTokenizationAfter, + stopRenderingLineAfter: opts.stopRenderingLineAfter, + longLineBoundary: opts.longLineBoundary, + forcedTokenizationBoundary: opts.forcedTokenizationBoundary, + hover: opts.hover, + contextmenu: opts.contextmenu, + quickSuggestions: opts.quickSuggestions, + quickSuggestionsDelay: opts.quickSuggestionsDelay, + iconsInSuggestions: opts.iconsInSuggestions, + autoClosingBrackets: opts.autoClosingBrackets, + formatOnType: opts.formatOnType, + suggestOnTriggerCharacters: opts.suggestOnTriggerCharacters, + selectionHighlight: opts.selectionHighlight, + outlineMarkers: opts.outlineMarkers, + referenceInfos: opts.referenceInfos, + renderWhitespace: opts.renderWhitespace, + layoutInfo: { + width: opts.layoutInfo.width, + height: opts.layoutInfo.height, + glyphMarginLeft: opts.layoutInfo.glyphMarginLeft, + glyphMarginWidth: opts.layoutInfo.glyphMarginWidth, + glyphMarginHeight: opts.layoutInfo.glyphMarginHeight, + lineNumbersLeft: opts.layoutInfo.lineNumbersLeft, + lineNumbersWidth: opts.layoutInfo.lineNumbersWidth, + lineNumbersHeight: opts.layoutInfo.lineNumbersHeight, + decorationsLeft: opts.layoutInfo.decorationsLeft, + decorationsWidth: opts.layoutInfo.decorationsWidth, + decorationsHeight: opts.layoutInfo.decorationsHeight, + contentLeft: opts.layoutInfo.contentLeft, + contentWidth: opts.layoutInfo.contentWidth, + contentHeight: opts.layoutInfo.contentHeight, + verticalScrollbarWidth: opts.layoutInfo.verticalScrollbarWidth, + horizontalScrollbarHeight: opts.layoutInfo.horizontalScrollbarHeight, + overviewRuler:{ + width: opts.layoutInfo.overviewRuler.width, + height: opts.layoutInfo.overviewRuler.height, + top: opts.layoutInfo.overviewRuler.top, + right: opts.layoutInfo.overviewRuler.right, + } + }, + stylingInfo: { + editorClassName: opts.stylingInfo.editorClassName, + fontFamily: opts.stylingInfo.fontFamily, + fontSize: opts.stylingInfo.fontSize, + lineHeight: opts.stylingInfo.lineHeight, + }, + wrappingInfo: { + isViewportWrapping: opts.wrappingInfo.isViewportWrapping, + wrappingColumn: opts.wrappingInfo.wrappingColumn, + }, + indentInfo: { + tabSize: opts.indentInfo.tabSize, + insertSpaces: opts.indentInfo.insertSpaces, + }, + observedOuterWidth: opts.observedOuterWidth, + observedOuterHeight: opts.observedOuterHeight, + lineHeight: opts.lineHeight, + pageSize: opts.pageSize, + typicalHalfwidthCharacterWidth: opts.typicalHalfwidthCharacterWidth, + typicalFullwidthCharacterWidth: opts.typicalFullwidthCharacterWidth, + fontSize: opts.fontSize, + }; +} + class InternalEditorOptionsHelper { constructor() { @@ -444,6 +545,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements Ed public handlerDispatcher:EditorCommon.IHandlerDispatcher; public editor:EditorCommon.IInternalEditorOptions; + public editorClone:EditorCommon.IInternalEditorOptions; protected _configWithDefaults:ConfigurationWithDefaults; private _indentationGuesser:IIndentationGuesser; @@ -467,6 +569,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements Ed this.handlerDispatcher = new HandlerDispatcher(); this.editor = this._computeInternalOptions(); + this.editorClone = cloneInternalEditorOptions(this.editor); } public dispose(): void { @@ -476,6 +579,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements Ed protected _recomputeOptions(): void { let oldOpts = this.editor; this.editor = this._computeInternalOptions(); + this.editorClone = cloneInternalEditorOptions(this.editor); let changeEvent = InternalEditorOptionsHelper.createConfigurationChangedEvent(oldOpts, this.editor); diff --git a/src/vs/editor/common/model/model.ts b/src/vs/editor/common/model/model.ts index 06311430847..7da9b08ec11 100644 --- a/src/vs/editor/common/model/model.ts +++ b/src/vs/editor/common/model/model.ts @@ -155,6 +155,7 @@ export class Model extends EditableTextModel implements EditorCommon.IModel { throw new Error('Model.getProperties: Model is disposed'); } + // TODO@Alex: avoid Objects.clone return Objects.clone(this._extraProperties); } diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index c55d2bff812..3c01592b463 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -8,7 +8,7 @@ import 'vs/css!./media/editorstatus'; import nls = require('vs/nls'); import {TPromise} from 'vs/base/common/winjs.base'; -import { emmet as $, append, show, hide } from 'vs/base/browser/dom'; +import { emmet as $, append } from 'vs/base/browser/dom'; import encoding = require('vs/base/common/bits/encoding'); import strings = require('vs/base/common/strings'); import types = require('vs/base/common/types'); @@ -21,6 +21,7 @@ import {Registry} from 'vs/platform/platform'; import {UntitledEditorInput} from 'vs/workbench/common/editor/untitledEditorInput'; import {IFileEditorInput, EncodingMode, IEncodingSupport, asFileEditorInput, getUntitledOrFileResource} from 'vs/workbench/common/editor'; import {IDisposable, combinedDispose} from 'vs/base/common/lifecycle'; +import {ICommonCodeEditor} from 'vs/editor/common/editorCommon'; import {ICodeEditor, IDiffEditor} from 'vs/editor/browser/editorBrowser'; import {EndOfLineSequence, ITokenizedModel, EditorType, IEditorSelection, ITextModel, IDiffEditorModel, IEditor} from 'vs/editor/common/editorCommon'; import {EventType, ResourceEvent, EditorEvent, TextEditorSelectionEvent} from 'vs/workbench/common/events'; @@ -33,6 +34,21 @@ import {IEventService} from 'vs/platform/event/common/event'; import {IFilesConfiguration} from 'vs/platform/files/common/files'; import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation'; import {IModeService} from 'vs/editor/common/services/modeService'; +import {StyleMutator} from 'vs/base/browser/styleMutator'; + +function getCodeEditor(e: IBaseEditor): ICommonCodeEditor { + if (e instanceof BaseTextEditor) { + let editorWidget = e.getControl(); + if (editorWidget.getEditorType() === EditorType.IDiffEditor) { + return (editorWidget).getModifiedEditor(); + } + if (editorWidget.getEditorType() === EditorType.ICodeEditor) { + return (editorWidget); + } + return null; + } + return null; +} function getTextModel(editorWidget: IEditor): ITextModel { let textModel: ITextModel; @@ -165,6 +181,13 @@ const nlsEOLLF = nls.localize('endOfLineLineFeed', "LF"); const nlsEOLCRLF = nls.localize('endOfLineCarriageReturnLineFeed', "CRLF"); const nlsTabFocusMode = nls.localize('tabFocusModeEnabled', "Tab moves focus"); +function show(el:HTMLElement): void { + StyleMutator.setDisplay(el, ''); +} +function hide(el:HTMLElement): void { + StyleMutator.setDisplay(el, 'none'); +} + export class EditorStatus implements IStatusbarItem { private state: State; @@ -408,15 +431,15 @@ export class EditorStatus implements IStatusbarItem { return; } - let info: StateDelta = { EOL: null }; + let codeEditor = getCodeEditor(e); + if (!codeEditor) { + return; + } - // We only support writable text based code editors - if (e instanceof BaseTextEditor && isWritableCodeEditor(e)) { - let editorWidget = e.getControl(); - let textModel = getTextModel(editorWidget); - if (textModel) { - info = { EOL: textModel.getEOL() }; - } + let info: StateDelta = { EOL: null }; + if (!codeEditor.getConfiguration().readOnly) { + let codeEditorModel = codeEditor.getModel(); + info.EOL = codeEditorModel.getEOL(); } this.updateState(info); -- GitLab