Skip to content

Commit 8bc62f0

Browse files
committed
Reduce usage of ICommonCodeEditor (microsoft#37834)
1 parent dc517c0 commit 8bc62f0

10 files changed

Lines changed: 154 additions & 99 deletions

File tree

src/vs/editor/browser/editorBrowser.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import { IMouseEvent } from 'vs/base/browser/mouseEvent';
1010
import { IConstructorSignature1 } from 'vs/platform/instantiation/common/instantiation';
1111
import * as editorCommon from 'vs/editor/common/editorCommon';
1212
import { Position, IPosition } from 'vs/editor/common/core/position';
13-
import { Range, IRange } from 'vs/editor/common/core/range';
13+
import { Range } from 'vs/editor/common/core/range';
1414
import * as editorOptions from 'vs/editor/common/config/editorOptions';
1515
import { OverviewRulerZone } from 'vs/editor/common/view/overviewZoneManager';
16-
import { IEditorWhitespace } from 'vs/editor/common/viewLayout/whitespaceComputer';
1716

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

408-
/**
409-
* Returns the range that is currently centered in the view port.
410-
*/
411-
getCenteredRangeInViewport(): Range;
412-
413-
/**
414-
* Get the view zones.
415-
* @internal
416-
*/
417-
getWhitespaces(): IEditorWhitespace[];
418-
419407
/**
420408
* Get the horizontal position (left offset) for the column w.r.t to the beginning of the line.
421409
* This method works only if the line `lineNumber` is currently rendered (in the editor's viewport).
@@ -428,16 +416,6 @@ export interface ICodeEditor extends editorCommon.ICommonCodeEditor {
428416
*/
429417
render(): void;
430418

431-
/**
432-
* Get the vertical position (top offset) for the line w.r.t. to the first line.
433-
*/
434-
getTopForLineNumber(lineNumber: number): number;
435-
436-
/**
437-
* Get the vertical position (top offset) for the position w.r.t. to the first line.
438-
*/
439-
getTopForPosition(lineNumber: number, column: number): number;
440-
441419
/**
442420
* Get the hit test target at coordinates `clientX` and `clientY`.
443421
* The coordinates are relative to the top-left of the viewport.
@@ -455,12 +433,6 @@ export interface ICodeEditor extends editorCommon.ICommonCodeEditor {
455433
*/
456434
getScrolledVisiblePosition(position: IPosition): { top: number; left: number; height: number; };
457435

458-
/**
459-
* Set the model ranges that will be hidden in the view.
460-
* @internal
461-
*/
462-
setHiddenAreas(ranges: IRange[]): void;
463-
464436
/**
465437
* @internal
466438
*/

src/vs/editor/browser/widget/codeEditorWidget.ts

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
1414
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1515
import { CommonCodeEditor } from 'vs/editor/common/commonCodeEditor';
1616
import { CommonEditorConfiguration } from 'vs/editor/common/config/commonEditorConfig';
17-
import { Range, IRange } from 'vs/editor/common/core/range';
17+
import { Range } from 'vs/editor/common/core/range';
1818
import * as editorCommon from 'vs/editor/common/editorCommon';
1919
import { EditorAction } from 'vs/editor/common/editorCommonExtensions';
2020
import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService';
@@ -27,7 +27,6 @@ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
2727
import { InternalEditorAction } from 'vs/editor/common/editorAction';
2828
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
2929
import { IPosition } from 'vs/editor/common/core/position';
30-
import { IEditorWhitespace } from 'vs/editor/common/viewLayout/whitespaceComputer';
3130
import { CoreEditorCommand } from 'vs/editor/common/controller/coreCommands';
3231
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
3332
import { editorErrorForeground, editorErrorBorder, editorWarningForeground, editorWarningBorder, editorInfoBorder, editorInfoForeground } from 'vs/editor/common/view/editorColorRegistry';
@@ -292,36 +291,6 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
292291
}
293292
}
294293

295-
public getWhitespaces(): IEditorWhitespace[] {
296-
if (!this.hasView) {
297-
return [];
298-
}
299-
return this.viewModel.viewLayout.getWhitespaces();
300-
}
301-
302-
private _getVerticalOffsetForPosition(modelLineNumber: number, modelColumn: number): number {
303-
let modelPosition = this.model.validatePosition({
304-
lineNumber: modelLineNumber,
305-
column: modelColumn
306-
});
307-
let viewPosition = this.viewModel.coordinatesConverter.convertModelPositionToViewPosition(modelPosition);
308-
return this.viewModel.viewLayout.getVerticalOffsetForLineNumber(viewPosition.lineNumber);
309-
}
310-
311-
public getTopForLineNumber(lineNumber: number): number {
312-
if (!this.hasView) {
313-
return -1;
314-
}
315-
return this._getVerticalOffsetForPosition(lineNumber, 1);
316-
}
317-
318-
public getTopForPosition(lineNumber: number, column: number): number {
319-
if (!this.hasView) {
320-
return -1;
321-
}
322-
return this._getVerticalOffsetForPosition(lineNumber, column);
323-
}
324-
325294
public getTargetAtClientPoint(clientX: number, clientY: number): editorBrowser.IMouseTarget {
326295
if (!this.hasView) {
327296
return null;
@@ -361,12 +330,6 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito
361330
this._view.render(true, false);
362331
}
363332

364-
public setHiddenAreas(ranges: IRange[]): void {
365-
if (this.viewModel) {
366-
this.viewModel.setHiddenAreas(ranges.map(r => Range.lift(r)));
367-
}
368-
}
369-
370333
public setAriaActiveDescendant(id: string): void {
371334
if (!this.hasView) {
372335
return;
@@ -542,4 +505,4 @@ registerThemingParticipant((theme, collector) => {
542505
if (warningForeground) {
543506
collector.addRule(`.monaco-editor .infosquiggly { background: url("data:image/svg+xml;utf8,${getSquigglySVGData(infoForeground)}") repeat-x bottom left; }`);
544507
}
545-
});
508+
});

src/vs/editor/common/commonCodeEditor.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
3131
import { CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
3232
import { VerticalRevealType } from 'vs/editor/common/view/viewEvents';
3333
import { ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDecorations';
34+
import { IEditorWhitespace } from 'vs/editor/common/viewLayout/whitespaceComputer';
3435

3536
let EDITOR_ID = 0;
3637

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

265+
public getWhitespaces(): IEditorWhitespace[] {
266+
if (!this.hasView) {
267+
return [];
268+
}
269+
return this.viewModel.viewLayout.getWhitespaces();
270+
}
271+
272+
protected _getVerticalOffsetForPosition(modelLineNumber: number, modelColumn: number): number {
273+
let modelPosition = this.model.validatePosition({
274+
lineNumber: modelLineNumber,
275+
column: modelColumn
276+
});
277+
let viewPosition = this.viewModel.coordinatesConverter.convertModelPositionToViewPosition(modelPosition);
278+
return this.viewModel.viewLayout.getVerticalOffsetForLineNumber(viewPosition.lineNumber);
279+
}
280+
281+
public getTopForLineNumber(lineNumber: number): number {
282+
if (!this.hasView) {
283+
return -1;
284+
}
285+
return this._getVerticalOffsetForPosition(lineNumber, 1);
286+
}
287+
288+
public getTopForPosition(lineNumber: number, column: number): number {
289+
if (!this.hasView) {
290+
return -1;
291+
}
292+
return this._getVerticalOffsetForPosition(lineNumber, column);
293+
}
294+
295+
public setHiddenAreas(ranges: IRange[]): void {
296+
if (this.viewModel) {
297+
this.viewModel.setHiddenAreas(ranges.map(r => Range.lift(r)));
298+
}
299+
}
300+
264301
public getVisibleColumnFromPosition(rawPosition: IPosition): number {
265302
if (!this.model) {
266303
return rawPosition.column;

src/vs/editor/common/editorCommon.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import * as editorOptions from 'vs/editor/common/config/editorOptions';
2525
import { ICursorPositionChangedEvent, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
2626
import { ICursors, CursorConfiguration } from 'vs/editor/common/controller/cursorCommon';
2727
import { ThemeColor } from 'vs/platform/theme/common/themeService';
28+
import { IEditorWhitespace } from 'vs/editor/common/viewLayout/whitespaceComputer';
2829

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

1978+
/**
1979+
* Returns the range that is currently centered in the view port.
1980+
*/
1981+
getCenteredRangeInViewport(): Range;
1982+
1983+
/**
1984+
* Get the view zones.
1985+
* @internal
1986+
*/
1987+
getWhitespaces(): IEditorWhitespace[];
1988+
1989+
/**
1990+
* Get the vertical position (top offset) for the line w.r.t. to the first line.
1991+
*/
1992+
getTopForLineNumber(lineNumber: number): number;
1993+
1994+
/**
1995+
* Get the vertical position (top offset) for the position w.r.t. to the first line.
1996+
*/
1997+
getTopForPosition(lineNumber: number, column: number): number;
1998+
1999+
/**
2000+
* Set the model ranges that will be hidden in the view.
2001+
* @internal
2002+
*/
2003+
setHiddenAreas(ranges: IRange[]): void;
2004+
19772005
/**
19782006
* @internal
19792007
*/

src/vs/editor/contrib/multicursor/common/multicursor.ts renamed to src/vs/editor/contrib/multicursor/multicursor.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as nls from 'vs/nls';
88
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
99
import { KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
1010
import { RunOnceScheduler } from 'vs/base/common/async';
11-
import { ICommonCodeEditor, ScrollType, IEditorContribution, FindMatch, TrackedRangeStickiness, OverviewRulerLane, IModel } from 'vs/editor/common/editorCommon';
11+
import { ScrollType, IEditorContribution, FindMatch, TrackedRangeStickiness, OverviewRulerLane, IModel } from 'vs/editor/common/editorCommon';
1212
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
1313
import { registerEditorAction, registerCommonEditorContribution, ServicesAccessor, EditorAction } from 'vs/editor/common/editorCommonExtensions';
1414
import { Range } from 'vs/editor/common/core/range';
@@ -23,6 +23,7 @@ import { ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDeco
2323
import { overviewRulerSelectionHighlightForeground } from 'vs/platform/theme/common/colorRegistry';
2424
import { themeColorFromId } from 'vs/platform/theme/common/themeService';
2525
import { INewFindReplaceState, FindOptionOverride } from 'vs/editor/contrib/find/common/findState';
26+
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
2627

2728
export class InsertCursorAbove extends EditorAction {
2829
constructor() {
@@ -42,7 +43,7 @@ export class InsertCursorAbove extends EditorAction {
4243
});
4344
}
4445

45-
public run(accessor: ServicesAccessor, editor: ICommonCodeEditor, args: any): void {
46+
public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
4647
const cursors = editor._getCursors();
4748
const context = cursors.context;
4849

@@ -81,7 +82,7 @@ export class InsertCursorBelow extends EditorAction {
8182
});
8283
}
8384

84-
public run(accessor: ServicesAccessor, editor: ICommonCodeEditor, args: any): void {
85+
public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
8586
const cursors = editor._getCursors();
8687
const context = cursors.context;
8788

@@ -117,7 +118,7 @@ class InsertCursorAtEndOfEachLineSelected extends EditorAction {
117118
});
118119
}
119120

120-
private getCursorsForSelection(selection: Selection, editor: ICommonCodeEditor): Selection[] {
121+
private getCursorsForSelection(selection: Selection, editor: ICodeEditor): Selection[] {
121122
if (selection.isEmpty()) {
122123
return [];
123124
}
@@ -135,7 +136,7 @@ class InsertCursorAtEndOfEachLineSelected extends EditorAction {
135136
return newSelections;
136137
}
137138

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

158159
export class MultiCursorSession {
159160

160-
public static create(editor: ICommonCodeEditor, findController: CommonFindController): MultiCursorSession {
161+
public static create(editor: ICodeEditor, findController: CommonFindController): MultiCursorSession {
161162
const findState = findController.getState();
162163

163164
// Find widget owns entirely what we search for if:
@@ -206,7 +207,7 @@ export class MultiCursorSession {
206207
}
207208

208209
constructor(
209-
private readonly _editor: ICommonCodeEditor,
210+
private readonly _editor: ICodeEditor,
210211
public readonly findController: CommonFindController,
211212
public readonly isDisconnectedFromFindController: boolean,
212213
public readonly searchText: string,
@@ -304,16 +305,16 @@ export class MultiCursorSelectionController extends Disposable implements IEdito
304305

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

307-
private readonly _editor: ICommonCodeEditor;
308+
private readonly _editor: ICodeEditor;
308309
private _ignoreSelectionChange: boolean;
309310
private _session: MultiCursorSession;
310311
private _sessionDispose: IDisposable[];
311312

312-
public static get(editor: ICommonCodeEditor): MultiCursorSelectionController {
313+
public static get(editor: ICodeEditor): MultiCursorSelectionController {
313314
return editor.getContribution<MultiCursorSelectionController>(MultiCursorSelectionController.ID);
314315
}
315316

316-
constructor(editor: ICommonCodeEditor) {
317+
constructor(editor: ICodeEditor) {
317318
super();
318319
this._editor = editor;
319320
this._ignoreSelectionChange = false;
@@ -502,7 +503,7 @@ export class MultiCursorSelectionController extends Disposable implements IEdito
502503

503504
export abstract class MultiCursorSelectionControllerAction extends EditorAction {
504505

505-
public run(accessor: ServicesAccessor, editor: ICommonCodeEditor): void {
506+
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
506507
const multiCursorController = MultiCursorSelectionController.get(editor);
507508
if (!multiCursorController) {
508509
return;
@@ -655,13 +656,13 @@ class SelectionHighlighterState {
655656
export class SelectionHighlighter extends Disposable implements IEditorContribution {
656657
private static ID = 'editor.contrib.selectionHighlighter';
657658

658-
private editor: ICommonCodeEditor;
659+
private editor: ICodeEditor;
659660
private _isEnabled: boolean;
660661
private decorations: string[];
661662
private updateSoon: RunOnceScheduler;
662663
private state: SelectionHighlighterState;
663664

664-
constructor(editor: ICommonCodeEditor) {
665+
constructor(editor: ICodeEditor) {
665666
super();
666667
this.editor = editor;
667668
this._isEnabled = editor.getConfiguration().contribInfo.selectionHighlight;
@@ -711,7 +712,7 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
711712
this._setState(SelectionHighlighter._createState(this._isEnabled, this.editor));
712713
}
713714

714-
private static _createState(isEnabled: boolean, editor: ICommonCodeEditor): SelectionHighlighterState {
715+
private static _createState(isEnabled: boolean, editor: ICodeEditor): SelectionHighlighterState {
715716
if (!isEnabled) {
716717
return null;
717718
}

src/vs/editor/contrib/multicursor/test/multicursor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as assert from 'assert';
88
import { withTestCodeEditor, TestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
99
import { Selection } from 'vs/editor/common/core/selection';
1010
import { Range } from 'vs/editor/common/core/range';
11-
import { InsertCursorAbove, InsertCursorBelow, MultiCursorSelectionController, SelectHighlightsAction, AddSelectionToNextFindMatchAction } from 'vs/editor/contrib/multicursor/common/multicursor';
11+
import { InsertCursorAbove, InsertCursorBelow, MultiCursorSelectionController, SelectHighlightsAction, AddSelectionToNextFindMatchAction } from 'vs/editor/contrib/multicursor/multicursor';
1212
import { Handler, EndOfLineSequence } from 'vs/editor/common/editorCommon';
1313
import { IStorageService } from 'vs/platform/storage/common/storage';
1414
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';

src/vs/editor/editor.all.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import 'vs/editor/contrib/hover/browser/hover';
3030
import 'vs/editor/contrib/inPlaceReplace/common/inPlaceReplace';
3131
import 'vs/editor/contrib/linesOperations/common/linesOperations';
3232
import 'vs/editor/contrib/links/browser/links';
33-
import 'vs/editor/contrib/multicursor/common/multicursor';
33+
import 'vs/editor/contrib/multicursor/multicursor';
3434
import 'vs/editor/contrib/parameterHints/browser/parameterHints';
3535
import 'vs/editor/contrib/quickFix/browser/quickFixCommands';
3636
import 'vs/editor/contrib/referenceSearch/browser/referenceSearch';
@@ -41,4 +41,4 @@ import 'vs/editor/contrib/suggest/browser/suggestController';
4141
import 'vs/editor/contrib/toggleTabFocusMode/common/toggleTabFocusMode';
4242
import 'vs/editor/contrib/wordHighlighter/common/wordHighlighter';
4343
import 'vs/editor/contrib/wordOperations/common/wordOperations';
44-
import 'vs/editor/contrib/colorPicker/browser/colorDetector';
44+
import 'vs/editor/contrib/colorPicker/browser/colorDetector';

0 commit comments

Comments
 (0)