|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { Emitter } from 'vs/base/common/event'; |
| 7 | +import { Disposable } from 'vs/base/common/lifecycle'; |
| 8 | +import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; |
| 9 | +import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; |
| 10 | +import { IDimension } from 'vs/editor/common/core/dimension'; |
| 11 | +import { IPosition, Position } from 'vs/editor/common/core/position'; |
| 12 | +import { IRange, Range } from 'vs/editor/common/core/range'; |
| 13 | +import { ISelection, Selection } from 'vs/editor/common/core/selection'; |
| 14 | +import { IEditor, IEditorAction, IEditorDecorationsCollection, IEditorModel, IEditorViewState, ScrollType } from 'vs/editor/common/editorCommon'; |
| 15 | +import { IModelDecorationsChangeAccessor, IModelDeltaDecoration } from 'vs/editor/common/model'; |
| 16 | + |
| 17 | +export abstract class DelegatingEditor extends Disposable implements IEditor { |
| 18 | + private static idCounter = 0; |
| 19 | + private readonly _id = ++DelegatingEditor.idCounter; |
| 20 | + |
| 21 | + private readonly _onDidDispose = this._register(new Emitter<void>()); |
| 22 | + public readonly onDidDispose = this._onDidDispose.event; |
| 23 | + |
| 24 | + protected abstract get _targetEditor(): CodeEditorWidget; |
| 25 | + |
| 26 | + getId(): string { return this.getEditorType() + ':' + this._id; } |
| 27 | + |
| 28 | + abstract getEditorType(): string; |
| 29 | + abstract updateOptions(newOptions: IEditorOptions): void; |
| 30 | + abstract onVisible(): void; |
| 31 | + abstract onHide(): void; |
| 32 | + abstract layout(dimension?: IDimension | undefined): void; |
| 33 | + abstract hasTextFocus(): boolean; |
| 34 | + abstract saveViewState(): IEditorViewState | null; |
| 35 | + abstract restoreViewState(state: IEditorViewState | null): void; |
| 36 | + abstract getModel(): IEditorModel | null; |
| 37 | + abstract setModel(model: IEditorModel | null): void; |
| 38 | + |
| 39 | + // #region editorBrowser.IDiffEditor: Delegating to modified Editor |
| 40 | + |
| 41 | + public getVisibleColumnFromPosition(position: IPosition): number { |
| 42 | + return this._targetEditor.getVisibleColumnFromPosition(position); |
| 43 | + } |
| 44 | + |
| 45 | + public getStatusbarColumn(position: IPosition): number { |
| 46 | + return this._targetEditor.getStatusbarColumn(position); |
| 47 | + } |
| 48 | + |
| 49 | + public getPosition(): Position | null { |
| 50 | + return this._targetEditor.getPosition(); |
| 51 | + } |
| 52 | + |
| 53 | + public setPosition(position: IPosition, source: string = 'api'): void { |
| 54 | + this._targetEditor.setPosition(position, source); |
| 55 | + } |
| 56 | + |
| 57 | + public revealLine(lineNumber: number, scrollType: ScrollType = ScrollType.Smooth): void { |
| 58 | + this._targetEditor.revealLine(lineNumber, scrollType); |
| 59 | + } |
| 60 | + |
| 61 | + public revealLineInCenter(lineNumber: number, scrollType: ScrollType = ScrollType.Smooth): void { |
| 62 | + this._targetEditor.revealLineInCenter(lineNumber, scrollType); |
| 63 | + } |
| 64 | + |
| 65 | + public revealLineInCenterIfOutsideViewport(lineNumber: number, scrollType: ScrollType = ScrollType.Smooth): void { |
| 66 | + this._targetEditor.revealLineInCenterIfOutsideViewport(lineNumber, scrollType); |
| 67 | + } |
| 68 | + |
| 69 | + public revealLineNearTop(lineNumber: number, scrollType: ScrollType = ScrollType.Smooth): void { |
| 70 | + this._targetEditor.revealLineNearTop(lineNumber, scrollType); |
| 71 | + } |
| 72 | + |
| 73 | + public revealPosition(position: IPosition, scrollType: ScrollType = ScrollType.Smooth): void { |
| 74 | + this._targetEditor.revealPosition(position, scrollType); |
| 75 | + } |
| 76 | + |
| 77 | + public revealPositionInCenter(position: IPosition, scrollType: ScrollType = ScrollType.Smooth): void { |
| 78 | + this._targetEditor.revealPositionInCenter(position, scrollType); |
| 79 | + } |
| 80 | + |
| 81 | + public revealPositionInCenterIfOutsideViewport(position: IPosition, scrollType: ScrollType = ScrollType.Smooth): void { |
| 82 | + this._targetEditor.revealPositionInCenterIfOutsideViewport(position, scrollType); |
| 83 | + } |
| 84 | + |
| 85 | + public revealPositionNearTop(position: IPosition, scrollType: ScrollType = ScrollType.Smooth): void { |
| 86 | + this._targetEditor.revealPositionNearTop(position, scrollType); |
| 87 | + } |
| 88 | + |
| 89 | + public getSelection(): Selection | null { |
| 90 | + return this._targetEditor.getSelection(); |
| 91 | + } |
| 92 | + |
| 93 | + public getSelections(): Selection[] | null { |
| 94 | + return this._targetEditor.getSelections(); |
| 95 | + } |
| 96 | + |
| 97 | + public setSelection(range: IRange, source?: string): void; |
| 98 | + public setSelection(editorRange: Range, source?: string): void; |
| 99 | + public setSelection(selection: ISelection, source?: string): void; |
| 100 | + public setSelection(editorSelection: Selection, source?: string): void; |
| 101 | + public setSelection(something: any, source: string = 'api'): void { |
| 102 | + this._targetEditor.setSelection(something, source); |
| 103 | + } |
| 104 | + |
| 105 | + public setSelections(ranges: readonly ISelection[], source: string = 'api'): void { |
| 106 | + this._targetEditor.setSelections(ranges, source); |
| 107 | + } |
| 108 | + |
| 109 | + public revealLines(startLineNumber: number, endLineNumber: number, scrollType: ScrollType = ScrollType.Smooth): void { |
| 110 | + this._targetEditor.revealLines(startLineNumber, endLineNumber, scrollType); |
| 111 | + } |
| 112 | + |
| 113 | + public revealLinesInCenter(startLineNumber: number, endLineNumber: number, scrollType: ScrollType = ScrollType.Smooth): void { |
| 114 | + this._targetEditor.revealLinesInCenter(startLineNumber, endLineNumber, scrollType); |
| 115 | + } |
| 116 | + |
| 117 | + public revealLinesInCenterIfOutsideViewport(startLineNumber: number, endLineNumber: number, scrollType: ScrollType = ScrollType.Smooth): void { |
| 118 | + this._targetEditor.revealLinesInCenterIfOutsideViewport(startLineNumber, endLineNumber, scrollType); |
| 119 | + } |
| 120 | + |
| 121 | + public revealLinesNearTop(startLineNumber: number, endLineNumber: number, scrollType: ScrollType = ScrollType.Smooth): void { |
| 122 | + this._targetEditor.revealLinesNearTop(startLineNumber, endLineNumber, scrollType); |
| 123 | + } |
| 124 | + |
| 125 | + public revealRange(range: IRange, scrollType: ScrollType = ScrollType.Smooth, revealVerticalInCenter: boolean = false, revealHorizontal: boolean = true): void { |
| 126 | + this._targetEditor.revealRange(range, scrollType, revealVerticalInCenter, revealHorizontal); |
| 127 | + } |
| 128 | + |
| 129 | + public revealRangeInCenter(range: IRange, scrollType: ScrollType = ScrollType.Smooth): void { |
| 130 | + this._targetEditor.revealRangeInCenter(range, scrollType); |
| 131 | + } |
| 132 | + |
| 133 | + public revealRangeInCenterIfOutsideViewport(range: IRange, scrollType: ScrollType = ScrollType.Smooth): void { |
| 134 | + this._targetEditor.revealRangeInCenterIfOutsideViewport(range, scrollType); |
| 135 | + } |
| 136 | + |
| 137 | + public revealRangeNearTop(range: IRange, scrollType: ScrollType = ScrollType.Smooth): void { |
| 138 | + this._targetEditor.revealRangeNearTop(range, scrollType); |
| 139 | + } |
| 140 | + |
| 141 | + public revealRangeNearTopIfOutsideViewport(range: IRange, scrollType: ScrollType = ScrollType.Smooth): void { |
| 142 | + this._targetEditor.revealRangeNearTopIfOutsideViewport(range, scrollType); |
| 143 | + } |
| 144 | + |
| 145 | + public revealRangeAtTop(range: IRange, scrollType: ScrollType = ScrollType.Smooth): void { |
| 146 | + this._targetEditor.revealRangeAtTop(range, scrollType); |
| 147 | + } |
| 148 | + |
| 149 | + public getSupportedActions(): IEditorAction[] { |
| 150 | + return this._targetEditor.getSupportedActions(); |
| 151 | + } |
| 152 | + |
| 153 | + public focus(): void { |
| 154 | + this._targetEditor.focus(); |
| 155 | + } |
| 156 | + |
| 157 | + public trigger(source: string | null | undefined, handlerId: string, payload: any): void { |
| 158 | + this._targetEditor.trigger(source, handlerId, payload); |
| 159 | + } |
| 160 | + |
| 161 | + public createDecorationsCollection(decorations?: IModelDeltaDecoration[]): IEditorDecorationsCollection { |
| 162 | + return this._targetEditor.createDecorationsCollection(decorations); |
| 163 | + } |
| 164 | + |
| 165 | + public changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any { |
| 166 | + return this._targetEditor.changeDecorations(callback); |
| 167 | + } |
| 168 | + |
| 169 | + // #endregion |
| 170 | +} |
0 commit comments