Skip to content

Commit

Permalink
Reduce usage of ICommonCodeEditor (#37834)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Nov 8, 2017
1 parent dc517c0 commit 8bc62f0
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 99 deletions.
30 changes: 1 addition & 29 deletions src/vs/editor/browser/editorBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import { IMouseEvent } from 'vs/base/browser/mouseEvent';
import { IConstructorSignature1 } from 'vs/platform/instantiation/common/instantiation';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { Position, IPosition } from 'vs/editor/common/core/position';
import { Range, IRange } from 'vs/editor/common/core/range';
import { Range } from 'vs/editor/common/core/range';
import * as editorOptions from 'vs/editor/common/config/editorOptions';
import { OverviewRulerZone } from 'vs/editor/common/view/overviewZoneManager';
import { IEditorWhitespace } from 'vs/editor/common/viewLayout/whitespaceComputer';

/**
* A view zone is a full horizontal rectangle that 'pushes' text down.
Expand Down Expand Up @@ -405,17 +404,6 @@ export interface ICodeEditor extends editorCommon.ICommonCodeEditor {
*/
changeViewZones(callback: (accessor: IViewZoneChangeAccessor) => void): void;

/**
* Returns the range that is currently centered in the view port.
*/
getCenteredRangeInViewport(): Range;

/**
* Get the view zones.
* @internal
*/
getWhitespaces(): IEditorWhitespace[];

/**
* Get the horizontal position (left offset) for the column w.r.t to the beginning of the line.
* This method works only if the line `lineNumber` is currently rendered (in the editor's viewport).
Expand All @@ -428,16 +416,6 @@ export interface ICodeEditor extends editorCommon.ICommonCodeEditor {
*/
render(): void;

/**
* Get the vertical position (top offset) for the line w.r.t. to the first line.
*/
getTopForLineNumber(lineNumber: number): number;

/**
* Get the vertical position (top offset) for the position w.r.t. to the first line.
*/
getTopForPosition(lineNumber: number, column: number): number;

/**
* Get the hit test target at coordinates `clientX` and `clientY`.
* The coordinates are relative to the top-left of the viewport.
Expand All @@ -455,12 +433,6 @@ export interface ICodeEditor extends editorCommon.ICommonCodeEditor {
*/
getScrolledVisiblePosition(position: IPosition): { top: number; left: number; height: number; };

/**
* Set the model ranges that will be hidden in the view.
* @internal
*/
setHiddenAreas(ranges: IRange[]): void;

/**
* @internal
*/
Expand Down
41 changes: 2 additions & 39 deletions src/vs/editor/browser/widget/codeEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { CommonCodeEditor } from 'vs/editor/common/commonCodeEditor';
import { CommonEditorConfiguration } from 'vs/editor/common/config/commonEditorConfig';
import { Range, IRange } from 'vs/editor/common/core/range';
import { Range } from 'vs/editor/common/core/range';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { EditorAction } from 'vs/editor/common/editorCommonExtensions';
import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService';
Expand All @@ -27,7 +27,6 @@ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { InternalEditorAction } from 'vs/editor/common/editorAction';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IPosition } from 'vs/editor/common/core/position';
import { IEditorWhitespace } from 'vs/editor/common/viewLayout/whitespaceComputer';
import { CoreEditorCommand } from 'vs/editor/common/controller/coreCommands';
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { editorErrorForeground, editorErrorBorder, editorWarningForeground, editorWarningBorder, editorInfoBorder, editorInfoForeground } from 'vs/editor/common/view/editorColorRegistry';
Expand Down Expand Up @@ -292,36 +291,6 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
}
}

public getWhitespaces(): IEditorWhitespace[] {
if (!this.hasView) {
return [];
}
return this.viewModel.viewLayout.getWhitespaces();
}

private _getVerticalOffsetForPosition(modelLineNumber: number, modelColumn: number): number {
let modelPosition = this.model.validatePosition({
lineNumber: modelLineNumber,
column: modelColumn
});
let viewPosition = this.viewModel.coordinatesConverter.convertModelPositionToViewPosition(modelPosition);
return this.viewModel.viewLayout.getVerticalOffsetForLineNumber(viewPosition.lineNumber);
}

public getTopForLineNumber(lineNumber: number): number {
if (!this.hasView) {
return -1;
}
return this._getVerticalOffsetForPosition(lineNumber, 1);
}

public getTopForPosition(lineNumber: number, column: number): number {
if (!this.hasView) {
return -1;
}
return this._getVerticalOffsetForPosition(lineNumber, column);
}

public getTargetAtClientPoint(clientX: number, clientY: number): editorBrowser.IMouseTarget {
if (!this.hasView) {
return null;
Expand Down Expand Up @@ -361,12 +330,6 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
this._view.render(true, false);
}

public setHiddenAreas(ranges: IRange[]): void {
if (this.viewModel) {
this.viewModel.setHiddenAreas(ranges.map(r => Range.lift(r)));
}
}

public setAriaActiveDescendant(id: string): void {
if (!this.hasView) {
return;
Expand Down Expand Up @@ -542,4 +505,4 @@ registerThemingParticipant((theme, collector) => {
if (warningForeground) {
collector.addRule(`.monaco-editor .infosquiggly { background: url("data:image/svg+xml;utf8,${getSquigglySVGData(infoForeground)}") repeat-x bottom left; }`);
}
});
});
37 changes: 37 additions & 0 deletions src/vs/editor/common/commonCodeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
import { VerticalRevealType } from 'vs/editor/common/view/viewEvents';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDecorations';
import { IEditorWhitespace } from 'vs/editor/common/viewLayout/whitespaceComputer';

let EDITOR_ID = 0;

Expand Down Expand Up @@ -261,6 +262,42 @@ export abstract class CommonCodeEditor extends Disposable implements editorCommo
return this.viewModel.getCenteredRangeInViewport();
}

public getWhitespaces(): IEditorWhitespace[] {
if (!this.hasView) {
return [];
}
return this.viewModel.viewLayout.getWhitespaces();
}

protected _getVerticalOffsetForPosition(modelLineNumber: number, modelColumn: number): number {
let modelPosition = this.model.validatePosition({
lineNumber: modelLineNumber,
column: modelColumn
});
let viewPosition = this.viewModel.coordinatesConverter.convertModelPositionToViewPosition(modelPosition);
return this.viewModel.viewLayout.getVerticalOffsetForLineNumber(viewPosition.lineNumber);
}

public getTopForLineNumber(lineNumber: number): number {
if (!this.hasView) {
return -1;
}
return this._getVerticalOffsetForPosition(lineNumber, 1);
}

public getTopForPosition(lineNumber: number, column: number): number {
if (!this.hasView) {
return -1;
}
return this._getVerticalOffsetForPosition(lineNumber, column);
}

public setHiddenAreas(ranges: IRange[]): void {
if (this.viewModel) {
this.viewModel.setHiddenAreas(ranges.map(r => Range.lift(r)));
}
}

public getVisibleColumnFromPosition(rawPosition: IPosition): number {
if (!this.model) {
return rawPosition.column;
Expand Down
28 changes: 28 additions & 0 deletions src/vs/editor/common/editorCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as editorOptions from 'vs/editor/common/config/editorOptions';
import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
import { ICursors, CursorConfiguration } from 'vs/editor/common/controller/cursorCommon';
import { ThemeColor } from 'vs/platform/theme/common/themeService';
import { IEditorWhitespace } from 'vs/editor/common/viewLayout/whitespaceComputer';

/**
* Vertical Lane in the overview ruler of the editor.
Expand Down Expand Up @@ -1974,6 +1975,33 @@ export interface ICommonCodeEditor extends IEditor {
*/
getLayoutInfo(): editorOptions.EditorLayoutInfo;

/**
* Returns the range that is currently centered in the view port.
*/
getCenteredRangeInViewport(): Range;

/**
* Get the view zones.
* @internal
*/
getWhitespaces(): IEditorWhitespace[];

/**
* Get the vertical position (top offset) for the line w.r.t. to the first line.
*/
getTopForLineNumber(lineNumber: number): number;

/**
* Get the vertical position (top offset) for the position w.r.t. to the first line.
*/
getTopForPosition(lineNumber: number, column: number): number;

/**
* Set the model ranges that will be hidden in the view.
* @internal
*/
setHiddenAreas(ranges: IRange[]): void;

/**
* @internal
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as nls from 'vs/nls';
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
import { KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
import { RunOnceScheduler } from 'vs/base/common/async';
import { ICommonCodeEditor, ScrollType, IEditorContribution, FindMatch, TrackedRangeStickiness, OverviewRulerLane, IModel } from 'vs/editor/common/editorCommon';
import { ScrollType, IEditorContribution, FindMatch, TrackedRangeStickiness, OverviewRulerLane, IModel } from 'vs/editor/common/editorCommon';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { registerEditorAction, registerCommonEditorContribution, ServicesAccessor, EditorAction } from 'vs/editor/common/editorCommonExtensions';
import { Range } from 'vs/editor/common/core/range';
Expand All @@ -23,6 +23,7 @@ import { ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDeco
import { overviewRulerSelectionHighlightForeground } from 'vs/platform/theme/common/colorRegistry';
import { themeColorFromId } from 'vs/platform/theme/common/themeService';
import { INewFindReplaceState, FindOptionOverride } from 'vs/editor/contrib/find/common/findState';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';

export class InsertCursorAbove extends EditorAction {
constructor() {
Expand All @@ -42,7 +43,7 @@ export class InsertCursorAbove extends EditorAction {
});
}

public run(accessor: ServicesAccessor, editor: ICommonCodeEditor, args: any): void {
public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
const cursors = editor._getCursors();
const context = cursors.context;

Expand Down Expand Up @@ -81,7 +82,7 @@ export class InsertCursorBelow extends EditorAction {
});
}

public run(accessor: ServicesAccessor, editor: ICommonCodeEditor, args: any): void {
public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
const cursors = editor._getCursors();
const context = cursors.context;

Expand Down Expand Up @@ -117,7 +118,7 @@ class InsertCursorAtEndOfEachLineSelected extends EditorAction {
});
}

private getCursorsForSelection(selection: Selection, editor: ICommonCodeEditor): Selection[] {
private getCursorsForSelection(selection: Selection, editor: ICodeEditor): Selection[] {
if (selection.isEmpty()) {
return [];
}
Expand All @@ -135,7 +136,7 @@ class InsertCursorAtEndOfEachLineSelected extends EditorAction {
return newSelections;
}

public run(accessor: ServicesAccessor, editor: ICommonCodeEditor): void {
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
let selections = editor.getSelections();
let newSelections = selections
.map((selection) => this.getCursorsForSelection(selection, editor))
Expand All @@ -157,7 +158,7 @@ export class MultiCursorSessionResult {

export class MultiCursorSession {

public static create(editor: ICommonCodeEditor, findController: CommonFindController): MultiCursorSession {
public static create(editor: ICodeEditor, findController: CommonFindController): MultiCursorSession {
const findState = findController.getState();

// Find widget owns entirely what we search for if:
Expand Down Expand Up @@ -206,7 +207,7 @@ export class MultiCursorSession {
}

constructor(
private readonly _editor: ICommonCodeEditor,
private readonly _editor: ICodeEditor,
public readonly findController: CommonFindController,
public readonly isDisconnectedFromFindController: boolean,
public readonly searchText: string,
Expand Down Expand Up @@ -304,16 +305,16 @@ export class MultiCursorSelectionController extends Disposable implements IEdito

private static ID = 'editor.contrib.multiCursorController';

private readonly _editor: ICommonCodeEditor;
private readonly _editor: ICodeEditor;
private _ignoreSelectionChange: boolean;
private _session: MultiCursorSession;
private _sessionDispose: IDisposable[];

public static get(editor: ICommonCodeEditor): MultiCursorSelectionController {
public static get(editor: ICodeEditor): MultiCursorSelectionController {
return editor.getContribution<MultiCursorSelectionController>(MultiCursorSelectionController.ID);
}

constructor(editor: ICommonCodeEditor) {
constructor(editor: ICodeEditor) {
super();
this._editor = editor;
this._ignoreSelectionChange = false;
Expand Down Expand Up @@ -502,7 +503,7 @@ export class MultiCursorSelectionController extends Disposable implements IEdito

export abstract class MultiCursorSelectionControllerAction extends EditorAction {

public run(accessor: ServicesAccessor, editor: ICommonCodeEditor): void {
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
const multiCursorController = MultiCursorSelectionController.get(editor);
if (!multiCursorController) {
return;
Expand Down Expand Up @@ -655,13 +656,13 @@ class SelectionHighlighterState {
export class SelectionHighlighter extends Disposable implements IEditorContribution {
private static ID = 'editor.contrib.selectionHighlighter';

private editor: ICommonCodeEditor;
private editor: ICodeEditor;
private _isEnabled: boolean;
private decorations: string[];
private updateSoon: RunOnceScheduler;
private state: SelectionHighlighterState;

constructor(editor: ICommonCodeEditor) {
constructor(editor: ICodeEditor) {
super();
this.editor = editor;
this._isEnabled = editor.getConfiguration().contribInfo.selectionHighlight;
Expand Down Expand Up @@ -711,7 +712,7 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
this._setState(SelectionHighlighter._createState(this._isEnabled, this.editor));
}

private static _createState(isEnabled: boolean, editor: ICommonCodeEditor): SelectionHighlighterState {
private static _createState(isEnabled: boolean, editor: ICodeEditor): SelectionHighlighterState {
if (!isEnabled) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/multicursor/test/multicursor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as assert from 'assert';
import { withTestCodeEditor, TestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
import { Selection } from 'vs/editor/common/core/selection';
import { Range } from 'vs/editor/common/core/range';
import { InsertCursorAbove, InsertCursorBelow, MultiCursorSelectionController, SelectHighlightsAction, AddSelectionToNextFindMatchAction } from 'vs/editor/contrib/multicursor/common/multicursor';
import { InsertCursorAbove, InsertCursorBelow, MultiCursorSelectionController, SelectHighlightsAction, AddSelectionToNextFindMatchAction } from 'vs/editor/contrib/multicursor/multicursor';
import { Handler, EndOfLineSequence } from 'vs/editor/common/editorCommon';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/editor.all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import 'vs/editor/contrib/hover/browser/hover';
import 'vs/editor/contrib/inPlaceReplace/common/inPlaceReplace';
import 'vs/editor/contrib/linesOperations/common/linesOperations';
import 'vs/editor/contrib/links/browser/links';
import 'vs/editor/contrib/multicursor/common/multicursor';
import 'vs/editor/contrib/multicursor/multicursor';
import 'vs/editor/contrib/parameterHints/browser/parameterHints';
import 'vs/editor/contrib/quickFix/browser/quickFixCommands';
import 'vs/editor/contrib/referenceSearch/browser/referenceSearch';
Expand All @@ -41,4 +41,4 @@ import 'vs/editor/contrib/suggest/browser/suggestController';
import 'vs/editor/contrib/toggleTabFocusMode/common/toggleTabFocusMode';
import 'vs/editor/contrib/wordHighlighter/common/wordHighlighter';
import 'vs/editor/contrib/wordOperations/common/wordOperations';
import 'vs/editor/contrib/colorPicker/browser/colorDetector';
import 'vs/editor/contrib/colorPicker/browser/colorDetector';

0 comments on commit 8bc62f0

Please sign in to comment.