Skip to content

Commit 0e7ef1f

Browse files
committed
Introduce and adopt ITextEditorOptions.selectionRevealType
1 parent 850d9d4 commit 0e7ef1f

11 files changed

Lines changed: 44 additions & 43 deletions

File tree

src/vs/editor/contrib/gotoError/gotoError.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { Action } from 'vs/base/common/actions';
2828
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
2929
import { isEqual } from 'vs/base/common/resources';
3030
import { IOpenerService } from 'vs/platform/opener/common/opener';
31+
import { TextEditorSelectionRevealType } from 'vs/platform/editor/common/editor';
3132

3233
class MarkerModel {
3334

@@ -396,7 +397,7 @@ class MarkerNavigationAction extends EditorAction {
396397

397398
return editorService.openCodeEditor({
398399
resource: newMarker.resource,
399-
options: { pinned: false, revealIfOpened: true, revealInCenterIfOutsideViewport: true, selection: newMarker }
400+
options: { pinned: false, revealIfOpened: true, selectionRevealType: TextEditorSelectionRevealType.CenterIfOutsideViewport, selection: newMarker }
400401
}, editor).then(editor => {
401402
if (!editor) {
402403
return undefined;

src/vs/editor/contrib/gotoSymbol/goToCommands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
3737
import { ScrollType, IEditorAction } from 'vs/editor/common/editorCommon';
3838
import { assertType } from 'vs/base/common/types';
3939
import { EmbeddedCodeEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
40+
import { TextEditorSelectionRevealType } from 'vs/platform/editor/common/editor';
4041

4142

4243
MenuRegistry.appendMenuItem(MenuId.EditorContext, <ISubmenuItem>{
@@ -166,7 +167,7 @@ abstract class SymbolNavigationAction extends EditorAction {
166167
resource: reference.uri,
167168
options: {
168169
selection: Range.collapseToStart(range),
169-
revealInCenterIfOutsideViewport: true
170+
selectionRevealType: TextEditorSelectionRevealType.CenterIfOutsideViewport
170171
}
171172
}, editor, sideBySide);
172173

src/vs/editor/contrib/gotoSymbol/symbolNavigation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { localize } from 'vs/nls';
1919
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
2020
import { INotificationService } from 'vs/platform/notification/common/notification';
2121
import { isEqual } from 'vs/base/common/resources';
22+
import { TextEditorSelectionRevealType } from 'vs/platform/editor/common/editor';
2223

2324
export const ctxHasSymbols = new RawContextKey('hasSymbols', false);
2425

@@ -127,7 +128,7 @@ class SymbolNavigationService implements ISymbolNavigationService {
127128
resource: reference.uri,
128129
options: {
129130
selection: Range.collapseToStart(reference.range),
130-
revealInCenterIfOutsideViewport: true
131+
selectionRevealType: TextEditorSelectionRevealType.CenterIfOutsideViewport
131132
}
132133
}, source).finally(() => {
133134
this._ignoreEditorChange = false;

src/vs/platform/editor/common/editor.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,21 @@ export interface ITextEditorSelection {
215215
readonly endColumn?: number;
216216
}
217217

218+
export const enum TextEditorSelectionRevealType {
219+
/**
220+
* Option to scroll vertically or horizontally as necessary and reveal a range centered vertically.
221+
*/
222+
Center = 0,
223+
/**
224+
* Option to scroll vertically or horizontally as necessary and reveal a range centered vertically only if it lies outside the viewport.
225+
*/
226+
CenterIfOutsideViewport = 1,
227+
/**
228+
* Option to scroll vertically or horizontally as necessary and reveal a range close to the top of the viewport, but not quite at the top.
229+
*/
230+
Definition = 2,
231+
}
232+
218233
export interface ITextEditorOptions extends IEditorOptions {
219234

220235
/**
@@ -228,14 +243,8 @@ export interface ITextEditorOptions extends IEditorOptions {
228243
readonly viewState?: object;
229244

230245
/**
231-
* Option to scroll vertically or horizontally as necessary and reveal a range centered vertically only if it lies outside the viewport.
232-
* This can't be used in combination with revealAtDefinition.
233-
*/
234-
readonly revealInCenterIfOutsideViewport?: boolean;
235-
236-
/**
237-
* Option to scroll vertically or horizontally as necessary and reveal a range close to the top of the viewport,
238-
* optimized for viewing a code definition.
246+
* Option to control the text editor selection reveal type.
247+
* Defaults to TextEditorSelectionRevealType.Center
239248
*/
240-
readonly revealAtDefinition?: boolean;
249+
readonly selectionRevealType?: TextEditorSelectionRevealType;
241250
}

src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { onDidChangeZoomLevel } from 'vs/base/browser/browser';
4848
import { withNullAsUndefined, withUndefinedAsNull } from 'vs/base/common/types';
4949
import { ILabelService } from 'vs/platform/label/common/label';
5050
import { ITextResourceConfigurationService } from 'vs/editor/common/services/textResourceConfigurationService';
51+
import { TextEditorSelectionRevealType } from 'vs/platform/editor/common/editor';
5152

5253
class Item extends BreadcrumbsItem {
5354

@@ -490,7 +491,7 @@ export class BreadcrumbsControl {
490491
resource: model.textModel.uri,
491492
options: {
492493
selection: Range.collapseToStart(element.symbol.selectionRange),
493-
revealInCenterIfOutsideViewport: true
494+
selectionRevealType: TextEditorSelectionRevealType.CenterIfOutsideViewport
494495
}
495496
}, withUndefinedAsNull(this._getActiveCodeEditor()), group === SIDE_GROUP);
496497
}

src/vs/workbench/common/editor.ts

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { withNullAsUndefined, assertIsDefined } from 'vs/base/common/types';
1010
import { URI } from 'vs/base/common/uri';
1111
import { IDisposable, Disposable, toDisposable } from 'vs/base/common/lifecycle';
1212
import { IEditor as ICodeEditor, IEditorViewState, ScrollType, IDiffEditor } from 'vs/editor/common/editorCommon';
13-
import { IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, IResourceInput, EditorActivation, EditorOpenContext, ITextEditorSelection } from 'vs/platform/editor/common/editor';
13+
import { IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, IResourceInput, EditorActivation, EditorOpenContext, ITextEditorSelection, TextEditorSelectionRevealType } from 'vs/platform/editor/common/editor';
1414
import { IInstantiationService, IConstructorSignature0, ServicesAccessor, BrandedService } from 'vs/platform/instantiation/common/instantiation';
1515
import { RawContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1616
import { Registry } from 'vs/platform/registry/common/platform';
@@ -1110,16 +1110,9 @@ export class TextEditorOptions extends EditorOptions implements ITextEditorOptio
11101110
editorViewState: IEditorViewState | undefined;
11111111

11121112
/**
1113-
* Option to scroll vertically or horizontally as necessary and reveal a range centered vertically only if it lies outside the viewport.
1114-
* This can't be used in combination with revealAtDefinition.
1113+
* Option to control the text editor selection reveal type.
11151114
*/
1116-
revealInCenterIfOutsideViewport: boolean | undefined;
1117-
1118-
/**
1119-
* Option to scroll vertically or horizontally as necessary and reveal a range close to the top of the viewport,
1120-
* optimized for viewing a code definition.
1121-
*/
1122-
revealAtDefinition: boolean | undefined;
1115+
selectionRevealType: TextEditorSelectionRevealType | undefined;
11231116

11241117
static from(input?: IBaseResourceInput): TextEditorOptions | undefined {
11251118
if (!input || !input.options) {
@@ -1158,15 +1151,8 @@ export class TextEditorOptions extends EditorOptions implements ITextEditorOptio
11581151
this.editorViewState = options.viewState as IEditorViewState;
11591152
}
11601153

1161-
if (typeof options.revealAtDefinition === 'boolean') {
1162-
this.revealAtDefinition = options.revealAtDefinition;
1163-
if (options.revealInCenterIfOutsideViewport) {
1164-
throw new Error('revealInCenterIfOutsideViewport and revealAtDefinition cannot both be true');
1165-
}
1166-
}
1167-
1168-
if (typeof options.revealInCenterIfOutsideViewport === 'boolean') {
1169-
this.revealInCenterIfOutsideViewport = options.revealInCenterIfOutsideViewport;
1154+
if (typeof options.selectionRevealType !== 'undefined') {
1155+
this.selectionRevealType = options.selectionRevealType;
11701156
}
11711157

11721158
return this;
@@ -1176,7 +1162,7 @@ export class TextEditorOptions extends EditorOptions implements ITextEditorOptio
11761162
* Returns if this options object has objects defined for the editor.
11771163
*/
11781164
hasOptionsDefined(): boolean {
1179-
return !!this.editorViewState || !!this.revealInCenterIfOutsideViewport || !!this.selection;
1165+
return !!this.editorViewState || !!this.selectionRevealType || !!this.selection;
11801166
}
11811167

11821168
/**
@@ -1216,9 +1202,9 @@ export class TextEditorOptions extends EditorOptions implements ITextEditorOptio
12161202

12171203
editor.setSelection(range);
12181204

1219-
if (this.revealAtDefinition) {
1205+
if (this.selectionRevealType === TextEditorSelectionRevealType.Definition) {
12201206
editor.revealRangeAtDefinition(range, scrollType);
1221-
} else if (this.revealInCenterIfOutsideViewport) {
1207+
} else if (this.selectionRevealType === TextEditorSelectionRevealType.CenterIfOutsideViewport) {
12221208
editor.revealRangeInCenterIfOutsideViewport(range, scrollType);
12231209
} else {
12241210
editor.revealRangeInCenter(range, scrollType);

src/vs/workbench/contrib/debug/browser/breakpointsView.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
3434
import { SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
3535
import { Gesture } from 'vs/base/browser/touch';
3636
import { IViewDescriptorService } from 'vs/workbench/common/views';
37+
import { TextEditorSelectionRevealType } from 'vs/platform/editor/common/editor';
3738

3839
const $ = dom.$;
3940

@@ -633,7 +634,7 @@ export function openBreakpointSource(breakpoint: IBreakpoint, sideBySide: boolea
633634
preserveFocus,
634635
selection,
635636
revealIfOpened: true,
636-
revealInCenterIfOutsideViewport: true,
637+
selectionRevealType: TextEditorSelectionRevealType.CenterIfOutsideViewport,
637638
pinned: !preserveFocus
638639
}
639640
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP);

src/vs/workbench/contrib/debug/common/debugSource.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/
1313
import { Schemas } from 'vs/base/common/network';
1414
import { isUri } from 'vs/workbench/contrib/debug/common/debugUtils';
1515
import { ITextEditor } from 'vs/workbench/common/editor';
16+
import { TextEditorSelectionRevealType } from 'vs/platform/editor/common/editor';
1617

1718
export const UNKNOWN_SOURCE_LABEL = nls.localize('unknownSource', "Unknown Source");
1819

@@ -101,7 +102,7 @@ export class Source {
101102
preserveFocus,
102103
selection,
103104
revealIfOpened: true,
104-
revealInCenterIfOutsideViewport: true,
105+
selectionRevealType: TextEditorSelectionRevealType.CenterIfOutsideViewport,
105106
pinned: pinned || (!preserveFocus && !this.inMemory)
106107
}
107108
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP);

src/vs/workbench/contrib/outline/browser/outlinePane.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { localize } from 'vs/nls';
2727
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2828
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2929
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
30-
import { IResourceInput } from 'vs/platform/editor/common/editor';
30+
import { IResourceInput, TextEditorSelectionRevealType } from 'vs/platform/editor/common/editor';
3131
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
3232
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
3333
import { WorkbenchDataTree } from 'vs/platform/list/browser/listService';
@@ -630,7 +630,7 @@ export class OutlinePane extends ViewPane {
630630
options: {
631631
preserveFocus: !focus,
632632
selection: Range.collapseToStart(element.symbol.selectionRange),
633-
revealAtDefinition: true,
633+
selectionRevealType: TextEditorSelectionRevealType.Definition,
634634
}
635635
} as IResourceInput, aside ? SIDE_GROUP : ACTIVE_GROUP);
636636
}

src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import { format } from 'vs/base/common/jsonFormatter';
7676
import { ITextModelService } from 'vs/editor/common/services/resolverService';
7777
import { applyEdits } from 'vs/base/common/jsonEdit';
7878
import { ITextEditor } from 'vs/workbench/common/editor';
79-
import { ITextEditorSelection } from 'vs/platform/editor/common/editor';
79+
import { ITextEditorSelection, TextEditorSelectionRevealType } from 'vs/platform/editor/common/editor';
8080
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
8181
import { find } from 'vs/base/common/arrays';
8282
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
@@ -968,7 +968,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
968968
pinned: false,
969969
forceReload: true, // because content might have changed
970970
selection,
971-
revealInCenterIfOutsideViewport: !!selection
971+
selectionRevealType: TextEditorSelectionRevealType.CenterIfOutsideViewport
972972
}
973973
});
974974
});

0 commit comments

Comments
 (0)