Skip to content

Commit

Permalink
Refactor editor options (#80469)
Browse files Browse the repository at this point in the history
Refactor editor options
  • Loading branch information
alexdima authored Sep 6, 2019
2 parents 9bb27be + 7b4c755 commit 9089a79
Show file tree
Hide file tree
Showing 121 changed files with 4,433 additions and 4,169 deletions.
3 changes: 3 additions & 0 deletions build/lib/tslint/noUnexternalizedStringsRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const Lint = require("tslint");
*/
class Rule extends Lint.Rules.AbstractRule {
apply(sourceFile) {
if (/\.d.ts$/.test(sourceFile.fileName)) {
return [];
}
return this.applyWithWalker(new NoUnexternalizedStringsRuleWalker(sourceFile, this.getOptions()));
}
}
Expand Down
3 changes: 3 additions & 0 deletions build/lib/tslint/noUnexternalizedStringsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import * as Lint from 'tslint';
*/
export class Rule extends Lint.Rules.AbstractRule {
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
if (/\.d.ts$/.test(sourceFile.fileName)) {
return [];
}
return this.applyWithWalker(new NoUnexternalizedStringsRuleWalker(sourceFile, this.getOptions()));
}
}
Expand Down
5 changes: 3 additions & 2 deletions build/monaco/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ function getMassagedTopLevelDeclarationText(sourceFile, declaration, importName,
}
});
}
result = result.replace(/export default/g, 'export');
result = result.replace(/export declare/g, 'export');
result = result.replace(/export default /g, 'export ');
result = result.replace(/export declare /g, 'export ');
result = result.replace(/declare /g, '');
if (declaration.kind === ts.SyntaxKind.EnumDeclaration) {
result = result.replace(/const enum/, 'enum');
enums.push(result);
Expand Down
5 changes: 3 additions & 2 deletions build/monaco/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ function getMassagedTopLevelDeclarationText(sourceFile: ts.SourceFile, declarati
}
});
}
result = result.replace(/export default/g, 'export');
result = result.replace(/export declare/g, 'export');
result = result.replace(/export default /g, 'export ');
result = result.replace(/export declare /g, 'export ');
result = result.replace(/declare /g, '');

if (declaration.kind === ts.SyntaxKind.EnumDeclaration) {
result = result.replace(/const enum/, 'enum');
Expand Down
1 change: 1 addition & 0 deletions build/monaco/monaco.d.ts.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface ICommandHandler {
#includeAll(vs/editor/common/editorCommon;editorOptions.=>): IScrollEvent
#includeAll(vs/editor/common/model/textModelEvents):
#includeAll(vs/editor/common/controller/cursorEvents):
#include(vs/platform/accessibility/common/accessibility): AccessibilitySupport
#includeAll(vs/editor/common/config/editorOptions):
#includeAll(vs/editor/browser/editorBrowser;editorCommon.=>;editorOptions.=>):
#include(vs/editor/common/config/fontInfo): FontInfo, BareFontInfo
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/browser/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as platform from 'vs/base/common/platform';
import { CharWidthRequest, CharWidthRequestType, readCharWidths } from 'vs/editor/browser/config/charWidthReader';
import { ElementSizeObserver } from 'vs/editor/browser/config/elementSizeObserver';
import { CommonEditorConfiguration, IEnvConfiguration } from 'vs/editor/common/config/commonEditorConfig';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IEditorOptions, EditorOption } from 'vs/editor/common/config/editorOptions';
import { BareFontInfo, FontInfo } from 'vs/editor/common/config/fontInfo';
import { IDimension } from 'vs/editor/common/editorCommon';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
Expand Down Expand Up @@ -320,7 +320,7 @@ export class Configuration extends CommonEditorConfiguration {

this._register(CSSBasedConfiguration.INSTANCE.onDidChange(() => this._onCSSBasedConfigurationChanged()));

if (this._validatedOptions.automaticLayout) {
if (this._validatedOptions.get(EditorOption.automaticLayout)) {
this._elementSizeObserver.startObserving();
}

Expand Down
12 changes: 8 additions & 4 deletions src/vs/editor/browser/controller/mouseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { HorizontalRange } from 'vs/editor/common/view/renderingContext';
import { ViewContext } from 'vs/editor/common/view/viewContext';
import * as viewEvents from 'vs/editor/common/view/viewEvents';
import { ViewEventHandler } from 'vs/editor/common/viewModel/viewEventHandler';
import { EditorOption } from 'vs/editor/common/config/editorOptions';


/**
* Merges mouse events when mouse move events are throttled
Expand Down Expand Up @@ -111,7 +113,7 @@ export class MouseHandler extends ViewEventHandler {
const onMouseWheel = (browserEvent: IMouseWheelEvent) => {
this.viewController.emitMouseWheel(browserEvent);

if (!this._context.configuration.editor.viewInfo.mouseWheelZoom) {
if (!this._context.configuration.options.get(EditorOption.mouseWheelZoom)) {
return;
}
const e = new StandardWheelEvent(browserEvent);
Expand Down Expand Up @@ -216,7 +218,7 @@ export class MouseHandler extends ViewEventHandler {
const targetIsContent = (t.type === editorBrowser.MouseTargetType.CONTENT_TEXT || t.type === editorBrowser.MouseTargetType.CONTENT_EMPTY);
const targetIsGutter = (t.type === editorBrowser.MouseTargetType.GUTTER_GLYPH_MARGIN || t.type === editorBrowser.MouseTargetType.GUTTER_LINE_NUMBERS || t.type === editorBrowser.MouseTargetType.GUTTER_LINE_DECORATIONS);
const targetIsLineNumbers = (t.type === editorBrowser.MouseTargetType.GUTTER_LINE_NUMBERS);
const selectOnLineNumbers = this._context.configuration.editor.viewInfo.selectOnLineNumbers;
const selectOnLineNumbers = this._context.configuration.options.get(EditorOption.selectOnLineNumbers);
const targetIsViewZone = (t.type === editorBrowser.MouseTargetType.CONTENT_VIEW_ZONE || t.type === editorBrowser.MouseTargetType.GUTTER_VIEW_ZONE);
const targetIsWidget = (t.type === editorBrowser.MouseTargetType.CONTENT_WIDGET);

Expand Down Expand Up @@ -351,8 +353,10 @@ class MouseDownOperation extends Disposable {
// Overwrite the detail of the MouseEvent, as it will be sent out in an event and contributions might rely on it.
e.detail = this._mouseState.count;

if (!this._context.configuration.editor.readOnly
&& this._context.configuration.editor.dragAndDrop
const options = this._context.configuration.options;

if (!options.get(EditorOption.readOnly)
&& options.get(EditorOption.dragAndDrop)
&& !this._mouseState.altKey // we don't support multiple mouse
&& e.detail < 2 // only single click on a selection can work
&& !this._isActive // the mouse is not down yet
Expand Down
14 changes: 8 additions & 6 deletions src/vs/editor/browser/controller/mouseTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ClientCoordinates, EditorMouseEvent, EditorPagePosition, PageCoordinate
import { PartFingerprint, PartFingerprints } from 'vs/editor/browser/view/viewPart';
import { ViewLine } from 'vs/editor/browser/viewParts/lines/viewLine';
import { IViewCursorRenderData } from 'vs/editor/browser/viewParts/viewCursors/viewCursor';
import { EditorLayoutInfo } from 'vs/editor/common/config/editorOptions';
import { EditorLayoutInfo, EditorOption } from 'vs/editor/common/config/editorOptions';
import { Position } from 'vs/editor/common/core/position';
import { Range as EditorRange } from 'vs/editor/common/core/range';
import { HorizontalRange } from 'vs/editor/common/view/renderingContext';
Expand Down Expand Up @@ -239,10 +239,11 @@ export class HitTestContext {

constructor(context: ViewContext, viewHelper: IPointerHandlerHelper, lastViewCursorsRenderData: IViewCursorRenderData[]) {
this.model = context.model;
this.layoutInfo = context.configuration.editor.layoutInfo;
const options = context.configuration.options;
this.layoutInfo = options.get(EditorOption.layoutInfo);
this.viewDomNode = viewHelper.viewDomNode;
this.lineHeight = context.configuration.editor.lineHeight;
this.typicalHalfwidthCharacterWidth = context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth;
this.lineHeight = options.get(EditorOption.lineHeight);
this.typicalHalfwidthCharacterWidth = options.get(EditorOption.fontInfo).typicalHalfwidthCharacterWidth;
this.lastViewCursorsRenderData = lastViewCursorsRenderData;
this._context = context;
this._viewHelper = viewHelper;
Expand Down Expand Up @@ -713,9 +714,10 @@ export class MouseTargetFactory {
}

public getMouseColumn(editorPos: EditorPagePosition, pos: PageCoordinates): number {
const layoutInfo = this._context.configuration.editor.layoutInfo;
const options = this._context.configuration.options;
const layoutInfo = options.get(EditorOption.layoutInfo);
const mouseContentHorizontalOffset = this._context.viewLayout.getCurrentScrollLeft() + pos.x - editorPos.x - layoutInfo.contentLeft;
return MouseTargetFactory._getMouseColumn(mouseContentHorizontalOffset, this._context.configuration.editor.fontInfo.typicalHalfwidthCharacterWidth);
return MouseTargetFactory._getMouseColumn(mouseContentHorizontalOffset, options.get(EditorOption.fontInfo).typicalHalfwidthCharacterWidth);
}

public static _getMouseColumn(mouseContentHorizontalOffset: number, typicalHalfwidthCharacterWidth: number): number {
Expand Down
87 changes: 45 additions & 42 deletions src/vs/editor/browser/controller/textAreaHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import 'vs/css!./textAreaHandler';
import * as nls from 'vs/nls';
import * as browser from 'vs/base/browser/browser';
import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
Expand All @@ -16,7 +17,7 @@ import { ViewController } from 'vs/editor/browser/view/viewController';
import { PartFingerprint, PartFingerprints, ViewPart } from 'vs/editor/browser/view/viewPart';
import { LineNumbersOverlay } from 'vs/editor/browser/viewParts/lineNumbers/lineNumbers';
import { Margin } from 'vs/editor/browser/viewParts/margin/margin';
import { RenderLineNumbersType } from 'vs/editor/common/config/editorOptions';
import { RenderLineNumbersType, EditorOption, IComputedEditorOptions } from 'vs/editor/common/config/editorOptions';
import { BareFontInfo } from 'vs/editor/common/config/fontInfo';
import { WordCharacterClass, getMapForWordSeparators } from 'vs/editor/common/controller/wordCharacterClassifier';
import { Position } from 'vs/editor/common/core/position';
Expand Down Expand Up @@ -91,12 +92,13 @@ export class TextAreaHandler extends ViewPart {

private readonly _viewController: ViewController;
private readonly _viewHelper: ITextAreaHandlerHelper;
private _scrollLeft: number;
private _scrollTop: number;

private _accessibilitySupport: AccessibilitySupport;
private _contentLeft: number;
private _contentWidth: number;
private _contentHeight: number;
private _scrollLeft: number;
private _scrollTop: number;
private _fontInfo: BareFontInfo;
private _lineHeight: number;
private _emptySelectionClipboard: boolean;
Expand All @@ -117,19 +119,20 @@ export class TextAreaHandler extends ViewPart {

this._viewController = viewController;
this._viewHelper = viewHelper;

const conf = this._context.configuration.editor;

this._accessibilitySupport = conf.accessibilitySupport;
this._contentLeft = conf.layoutInfo.contentLeft;
this._contentWidth = conf.layoutInfo.contentWidth;
this._contentHeight = conf.layoutInfo.contentHeight;
this._scrollLeft = 0;
this._scrollTop = 0;
this._fontInfo = conf.fontInfo;
this._lineHeight = conf.lineHeight;
this._emptySelectionClipboard = conf.emptySelectionClipboard;
this._copyWithSyntaxHighlighting = conf.copyWithSyntaxHighlighting;

const options = this._context.configuration.options;
const layoutInfo = options.get(EditorOption.layoutInfo);

this._accessibilitySupport = options.get(EditorOption.accessibilitySupport);
this._contentLeft = layoutInfo.contentLeft;
this._contentWidth = layoutInfo.contentWidth;
this._contentHeight = layoutInfo.contentHeight;
this._fontInfo = options.get(EditorOption.fontInfo);
this._lineHeight = options.get(EditorOption.lineHeight);
this._emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard);
this._copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting);

this._visibleTextArea = null;
this._selections = [new Selection(1, 1, 1, 1)];
Expand All @@ -143,7 +146,7 @@ export class TextAreaHandler extends ViewPart {
this.textArea.setAttribute('autocapitalize', 'off');
this.textArea.setAttribute('autocomplete', 'off');
this.textArea.setAttribute('spellcheck', 'false');
this.textArea.setAttribute('aria-label', conf.viewInfo.ariaLabel);
this.textArea.setAttribute('aria-label', this._getAriaLabel(options));
this.textArea.setAttribute('role', 'textbox');
this.textArea.setAttribute('aria-multiline', 'true');
this.textArea.setAttribute('aria-haspopup', 'false');
Expand Down Expand Up @@ -341,7 +344,7 @@ export class TextAreaHandler extends ViewPart {

private _getWordBeforePosition(position: Position): string {
const lineContent = this._context.model.getLineContent(position.lineNumber);
const wordSeparators = getMapForWordSeparators(this._context.configuration.editor.wordSeparators);
const wordSeparators = getMapForWordSeparators(this._context.configuration.options.get(EditorOption.wordSeparators));

let column = position.column;
let distance = 0;
Expand All @@ -368,35 +371,33 @@ export class TextAreaHandler extends ViewPart {
return '';
}

private _getAriaLabel(options: IComputedEditorOptions): string {
const accessibilitySupport = options.get(EditorOption.accessibilitySupport);
if (accessibilitySupport === AccessibilitySupport.Disabled) {
return nls.localize('accessibilityOffAriaLabel', "The editor is not accessible at this time. Press Alt+F1 for options.");
}
return options.get(EditorOption.ariaLabel);
}

// --- begin event handlers

public onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean {
const conf = this._context.configuration.editor;

if (e.fontInfo) {
this._fontInfo = conf.fontInfo;
}
if (e.viewInfo) {
this.textArea.setAttribute('aria-label', conf.viewInfo.ariaLabel);
}
if (e.layoutInfo) {
this._contentLeft = conf.layoutInfo.contentLeft;
this._contentWidth = conf.layoutInfo.contentWidth;
this._contentHeight = conf.layoutInfo.contentHeight;
}
if (e.lineHeight) {
this._lineHeight = conf.lineHeight;
}
if (e.accessibilitySupport) {
this._accessibilitySupport = conf.accessibilitySupport;
const options = this._context.configuration.options;
const layoutInfo = options.get(EditorOption.layoutInfo);

this._accessibilitySupport = options.get(EditorOption.accessibilitySupport);
this._contentLeft = layoutInfo.contentLeft;
this._contentWidth = layoutInfo.contentWidth;
this._contentHeight = layoutInfo.contentHeight;
this._fontInfo = options.get(EditorOption.fontInfo);
this._lineHeight = options.get(EditorOption.lineHeight);
this._emptySelectionClipboard = options.get(EditorOption.emptySelectionClipboard);
this._copyWithSyntaxHighlighting = options.get(EditorOption.copyWithSyntaxHighlighting);
this.textArea.setAttribute('aria-label', this._getAriaLabel(options));

if (e.hasChanged(EditorOption.accessibilitySupport)) {
this._textAreaInput.writeScreenReaderContent('strategy changed');
}
if (e.emptySelectionClipboard) {
this._emptySelectionClipboard = conf.emptySelectionClipboard;
}
if (e.copyWithSyntaxHighlighting) {
this._copyWithSyntaxHighlighting = conf.copyWithSyntaxHighlighting;
}

return true;
}
Expand Down Expand Up @@ -545,10 +546,12 @@ export class TextAreaHandler extends ViewPart {
tac.setWidth(1);
tac.setHeight(1);

if (this._context.configuration.editor.viewInfo.glyphMargin) {
const options = this._context.configuration.options;

if (options.get(EditorOption.glyphMargin)) {
tac.setClassName('monaco-editor-background textAreaCover ' + Margin.OUTER_CLASS_NAME);
} else {
if (this._context.configuration.editor.viewInfo.renderLineNumbers !== RenderLineNumbersType.Off) {
if (options.get(EditorOption.lineNumbers).renderType !== RenderLineNumbersType.Off) {
tac.setClassName('monaco-editor-background textAreaCover ' + LineNumbersOverlay.CLASS_NAME);
} else {
tac.setClassName('monaco-editor-background textAreaCover');
Expand Down
15 changes: 8 additions & 7 deletions src/vs/editor/browser/editorBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { IMouseEvent, IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
import { IDisposable } from 'vs/base/common/lifecycle';
import * as editorOptions from 'vs/editor/common/config/editorOptions';
import { OverviewRulerPosition, ConfigurationChangedEvent, EditorLayoutInfo, IComputedEditorOptions, EditorOption, FindComputedEditorOptionValueById, IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { ICursors } from 'vs/editor/common/controller/cursorCommon';
import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
import { IPosition, Position } from 'vs/editor/common/core/position';
Expand Down Expand Up @@ -315,7 +315,7 @@ export interface IOverviewRuler {
getDomNode(): HTMLElement;
dispose(): void;
setZones(zones: OverviewRulerZone[]): void;
setLayout(position: editorOptions.OverviewRulerPosition): void;
setLayout(position: OverviewRulerPosition): void;
}

/**
Expand Down Expand Up @@ -351,7 +351,7 @@ export interface ICodeEditor extends editorCommon.IEditor {
* An event emitted when the configuration of the editor has changed. (e.g. `editor.updateOptions()`)
* @event
*/
onDidChangeConfiguration(listener: (e: editorOptions.IConfigurationChangedEvent) => void): IDisposable;
onDidChangeConfiguration(listener: (e: ConfigurationChangedEvent) => void): IDisposable;
/**
* An event emitted when the cursor position has changed.
* @event
Expand Down Expand Up @@ -481,7 +481,7 @@ export interface ICodeEditor extends editorCommon.IEditor {
* An event emitted when the layout of the editor has changed.
* @event
*/
onDidLayoutChange(listener: (e: editorOptions.EditorLayoutInfo) => void): IDisposable;
onDidLayoutChange(listener: (e: EditorLayoutInfo) => void): IDisposable;
/**
* An event emitted when the scroll in the editor has changed.
* @event
Expand Down Expand Up @@ -534,13 +534,14 @@ export interface ICodeEditor extends editorCommon.IEditor {
/**
* Returns the current editor's configuration
*/
getConfiguration(): editorOptions.InternalEditorOptions;
getOptions(): IComputedEditorOptions;

getOption<T extends EditorOption>(id: T): FindComputedEditorOptionValueById<T>;
/**
* Returns the 'raw' editor's configuration (without any validation or defaults).
* @internal
*/
getRawConfiguration(): editorOptions.IEditorOptions;
getRawConfiguration(): IEditorOptions;

/**
* Get value of the current model attached to this editor.
Expand Down Expand Up @@ -655,7 +656,7 @@ export interface ICodeEditor extends editorCommon.IEditor {
/**
* Get the layout info for the editor.
*/
getLayoutInfo(): editorOptions.EditorLayoutInfo;
getLayoutInfo(): EditorLayoutInfo;

/**
* Returns the ranges that are currently visible.
Expand Down
5 changes: 3 additions & 2 deletions src/vs/editor/browser/view/viewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Selection } from 'vs/editor/common/core/selection';
import { IConfiguration } from 'vs/editor/common/editorCommon';
import { IViewModel } from 'vs/editor/common/viewModel/viewModel';
import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
import { EditorOption } from 'vs/editor/common/config/editorOptions';

export interface IMouseDispatchData {
position: Position;
Expand Down Expand Up @@ -107,7 +108,7 @@ export class ViewController {
}

private _hasMulticursorModifier(data: IMouseDispatchData): boolean {
switch (this.configuration.editor.multiCursorModifier) {
switch (this.configuration.options.get(EditorOption.multiCursorModifier)) {
case 'altKey':
return data.altKey;
case 'ctrlKey':
Expand All @@ -119,7 +120,7 @@ export class ViewController {
}

private _hasNonMulticursorModifier(data: IMouseDispatchData): boolean {
switch (this.configuration.editor.multiCursorModifier) {
switch (this.configuration.options.get(EditorOption.multiCursorModifier)) {
case 'altKey':
return data.ctrlKey || data.metaKey;
case 'ctrlKey':
Expand Down
Loading

0 comments on commit 9089a79

Please sign in to comment.