提交 f3a23697 编写于 作者: B Benjamin Pasero

Editors: revisit "preview" editors default behaviour (#109779)

Things done:
- set pinned more explicitly in many places
- flip the default of enablePreviewFromQuickOpen to false
- change lists/tree to pin if preserveFocus: false after opening
上级 d6c2656f
......@@ -117,17 +117,17 @@ export abstract class ReferencesController implements IEditorContribution {
if (event.source !== 'editor' || !this._configurationService.getValue('editor.stablePeek')) {
// when stable peek is configured we don't close
// the peek window on selecting the editor
this.openReference(element, false);
this.openReference(element, false, false);
}
break;
case 'side':
this.openReference(element, true);
this.openReference(element, true, false);
break;
case 'goto':
if (peekMode) {
this._gotoReference(element);
} else {
this.openReference(element, false);
this.openReference(element, false, true);
}
break;
}
......@@ -285,7 +285,7 @@ export abstract class ReferencesController implements IEditorContribution {
});
}
openReference(ref: Location, sideBySide: boolean): void {
openReference(ref: Location, sideBySide: boolean, pinned: boolean): void {
// clear stage
if (!sideBySide) {
this.closeWidget();
......@@ -294,7 +294,7 @@ export abstract class ReferencesController implements IEditorContribution {
const { uri, range } = ref;
this._editorService.openCodeEditor({
resource: uri,
options: { selection: range }
options: { selection: range, pinned }
}, this._editor, sideBySide);
}
}
......@@ -404,7 +404,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
const listService = accessor.get(IListService);
const focus = <any[]>listService.lastFocusedList?.getFocus();
if (Array.isArray(focus) && focus[0] instanceof OneReference) {
withController(accessor, controller => controller.openReference(focus[0], true));
withController(accessor, controller => controller.openReference(focus[0], true, true));
}
}
});
......@@ -413,6 +413,6 @@ CommandsRegistry.registerCommand('openReference', (accessor) => {
const listService = accessor.get(IListService);
const focus = <any[]>listService.lastFocusedList?.getFocus();
if (Array.isArray(focus) && focus[0] instanceof OneReference) {
withController(accessor, controller => controller.openReference(focus[0], false));
withController(accessor, controller => controller.openReference(focus[0], false, true));
}
});
......@@ -444,7 +444,7 @@ abstract class ResourceNavigator<T> extends Disposable {
private readonly openOnFocus: boolean;
private openOnSingleClick: boolean;
private readonly _onDidOpen = new Emitter<IOpenEvent<T | null>>();
private readonly _onDidOpen = this._register(new Emitter<IOpenEvent<T | null>>());
readonly onDidOpen: Event<IOpenEvent<T | null>> = this._onDidOpen.event;
constructor(
......@@ -478,7 +478,7 @@ abstract class ResourceNavigator<T> extends Disposable {
this.widget.setSelection(focus, event.browserEvent);
const preserveFocus = typeof (event.browserEvent as SelectionKeyboardEvent).preserveFocus === 'boolean' ? (event.browserEvent as SelectionKeyboardEvent).preserveFocus! : true;
const pinned = false;
const pinned = !preserveFocus;
const sideBySide = false;
this._open(preserveFocus, pinned, sideBySide, event.browserEvent);
......@@ -490,7 +490,7 @@ abstract class ResourceNavigator<T> extends Disposable {
}
const preserveFocus = typeof (event.browserEvent as SelectionKeyboardEvent).preserveFocus === 'boolean' ? (event.browserEvent as SelectionKeyboardEvent).preserveFocus! : true;
const pinned = false;
const pinned = !preserveFocus;
const sideBySide = false;
this._open(preserveFocus, pinned, sideBySide, event.browserEvent);
......
......@@ -141,7 +141,7 @@ export class OpenWorkspaceConfigFileAction extends Action {
async run(): Promise<void> {
const configuration = this.workspaceContextService.getWorkspace().configuration;
if (configuration) {
await this.editorService.openEditor({ resource: configuration });
await this.editorService.openEditor({ resource: configuration, options: { pinned: true } });
}
}
}
......
......@@ -491,7 +491,7 @@ export class BreadcrumbsControl {
if (element instanceof FileElement) {
if (element.kind === FileKind.FILE) {
// open file in any editor
this._editorService.openEditor({ resource: element.uri, options: { pinned: pinned } }, group);
this._editorService.openEditor({ resource: element.uri, options: { pinned } }, group);
} else {
// show next picker
let items = this._widget.getItems();
......@@ -508,7 +508,8 @@ export class BreadcrumbsControl {
resource: model.uri,
options: {
selection: Range.collapseToStart(element.symbol.selectionRange),
selectionRevealType: TextEditorSelectionRevealType.CenterIfOutsideViewport
selectionRevealType: TextEditorSelectionRevealType.CenterIfOutsideViewport,
pinned
}
}, withUndefinedAsNull(this._getActiveCodeEditor()), group === SIDE_GROUP);
}
......@@ -753,13 +754,14 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
// open symbol in editor
return editors.openEditor({
resource: outlineElement.uri,
options: { selection: Range.collapseToStart(element.symbol.selectionRange) }
options: { selection: Range.collapseToStart(element.symbol.selectionRange), pinned: true }
}, SIDE_GROUP);
} else if (element && URI.isUri(element.resource)) {
// open file in editor
return editors.openEditor({
resource: element.resource,
options: { pinned: true }
}, SIDE_GROUP);
} else {
......
......@@ -64,12 +64,12 @@ export interface IEditorOpeningEvent extends IEditorIdentifier {
/**
* The options used when opening the editor.
*/
options?: IEditorOptions;
readonly options?: IEditorOptions;
/**
* Context indicates how the editor open event is initialized.
*/
context?: OpenEditorContext;
readonly context?: OpenEditorContext;
/**
* Allows to prevent the opening of an editor by providing a callback
......
......@@ -1742,28 +1742,17 @@ class EditorOpeningEvent implements IEditorOpeningEvent {
private override: (() => Promise<IEditorPane | undefined>) | undefined = undefined;
constructor(
private _group: GroupIdentifier,
private _editor: EditorInput,
public readonly groupId: GroupIdentifier,
public readonly editor: EditorInput,
private _options: EditorOptions | undefined,
private _context: OpenEditorContext | undefined
public readonly context: OpenEditorContext | undefined
) {
}
get groupId(): GroupIdentifier {
return this._group;
}
get editor(): EditorInput {
return this._editor;
}
get options(): EditorOptions | undefined {
return this._options;
}
get context(): OpenEditorContext | undefined {
return this._context;
}
prevent(callback: () => Promise<IEditorPane | undefined>): void {
this.override = callback;
......@@ -1775,9 +1764,9 @@ class EditorOpeningEvent implements IEditorOpeningEvent {
}
export interface EditorReplacement {
editor: EditorInput;
replacement: EditorInput;
options?: EditorOptions;
readonly editor: EditorInput;
readonly replacement: EditorInput;
readonly options?: EditorOptions;
}
registerThemingParticipant((theme, collector, environment) => {
......
......@@ -126,7 +126,7 @@ import { isStandalone } from 'vs/base/browser/browser';
'workbench.editor.enablePreviewFromQuickOpen': {
'type': 'boolean',
'description': nls.localize('enablePreviewFromQuickOpen', "Controls whether editors opened from Quick Open show as preview. Preview editors are reused until they are explicitly set to be kept open (e.g. via double click or editing)."),
'default': true
'default': false
},
'workbench.editor.closeOnFileDelete': {
'type': 'boolean',
......
......@@ -277,7 +277,7 @@ export class CallHierarchyTreePeekWidget extends peekView.PeekViewWidget {
this.dispose();
this._editorService.openEditor({
resource: e.element.item.uri,
options: { selection: e.element.item.selectionRange }
options: { selection: e.element.item.selectionRange, pinned: true }
});
}
}));
......@@ -289,7 +289,7 @@ export class CallHierarchyTreePeekWidget extends peekView.PeekViewWidget {
this.dispose();
this._editorService.openEditor({
resource: element.item.uri,
options: { selection: element.item.selectionRange }
options: { selection: element.item.selectionRange, pinned: true }
});
}
}));
......
......@@ -70,7 +70,8 @@ class StartDebugTextMate extends Action {
};
await this._hostService.openWindow([{ fileUri: URI.file(pathInTemp) }], { forceNewWindow: true });
const textEditorPane = await this._editorService.openEditor({
resource: model.uri
resource: model.uri,
options: { pinned: true }
});
if (!textEditorPane) {
return;
......
......@@ -133,7 +133,7 @@ export class BreakpointsView extends ViewPane {
const element = this.list.element(e.element);
if (element instanceof Breakpoint) {
openBreakpointSource(element, e.sideBySide, e.editorOptions.preserveFocus || false, this.debugService, this.editorService);
openBreakpointSource(element, e.sideBySide, e.editorOptions.preserveFocus || false, e.editorOptions.pinned || !e.editorOptions.preserveFocus, this.debugService, this.editorService);
}
if (e.browserEvent instanceof MouseEvent && e.browserEvent.detail === 2 && element instanceof FunctionBreakpoint && element !== this.debugService.getViewModel().getSelectedFunctionBreakpoint()) {
// double click
......@@ -192,7 +192,7 @@ export class BreakpointsView extends ViewPane {
if (element instanceof Breakpoint || element instanceof FunctionBreakpoint) {
actions.push(new Action('workbench.action.debug.openEditorAndEditBreakpoint', nls.localize('editBreakpoint', "Edit {0}...", breakpointType), '', true, async () => {
if (element instanceof Breakpoint) {
const editor = await openBreakpointSource(element, false, false, this.debugService, this.editorService);
const editor = await openBreakpointSource(element, false, false, true, this.debugService, this.editorService);
if (editor) {
const codeEditor = editor.getControl();
if (isCodeEditor(codeEditor)) {
......@@ -671,7 +671,7 @@ class BreakpointsAccessibilityProvider implements IListAccessibilityProvider<Bre
}
}
export function openBreakpointSource(breakpoint: IBreakpoint, sideBySide: boolean, preserveFocus: boolean, debugService: IDebugService, editorService: IEditorService): Promise<IEditorPane | undefined> {
export function openBreakpointSource(breakpoint: IBreakpoint, sideBySide: boolean, preserveFocus: boolean, pinned: boolean, debugService: IDebugService, editorService: IEditorService): Promise<IEditorPane | undefined> {
if (breakpoint.uri.scheme === DEBUG_SCHEME && debugService.state === State.Inactive) {
return Promise.resolve(undefined);
}
......@@ -695,7 +695,7 @@ export function openBreakpointSource(breakpoint: IBreakpoint, sideBySide: boolea
selection,
revealIfOpened: true,
selectionRevealType: TextEditorSelectionRevealType.CenterIfOutsideViewport,
pinned: !preserveFocus
pinned
}
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP);
}
......
......@@ -564,7 +564,7 @@ export function registerCommands(): void {
if (list instanceof List) {
const focus = list.getFocusedElements();
if (focus.length && focus[0] instanceof Breakpoint) {
return openBreakpointSource(focus[0], true, false, accessor.get(IDebugService), accessor.get(IEditorService));
return openBreakpointSource(focus[0], true, false, true, accessor.get(IDebugService), accessor.get(IEditorService));
}
}
......
......@@ -336,7 +336,7 @@ class GoToBreakpointAction extends EditorAction {
}
if (moveBreakpoint) {
return openBreakpointSource(moveBreakpoint, false, true, debugService, editorService);
return openBreakpointSource(moveBreakpoint, false, true, false, debugService, editorService);
}
}
}
......
......@@ -58,7 +58,7 @@ export class ExtensionHostProfileService extends Disposable implements IExtensio
CommandsRegistry.registerCommand('workbench.action.extensionHostProfilder.stop', () => {
this.stopProfiling();
this._editorService.openEditor(RuntimeExtensionsInput.instance, { revealIfOpened: true });
this._editorService.openEditor(RuntimeExtensionsInput.instance, { revealIfOpened: true, pinned: true });
});
}
......
......@@ -187,7 +187,7 @@ export class ExtensionsAutoProfiler extends Disposable implements IWorkbenchCont
),
[{
label: localize('show', 'Show Extensions'),
run: () => this._editorService.openEditor(RuntimeExtensionsInput.instance)
run: () => this._editorService.openEditor(RuntimeExtensionsInput.instance, { pinned: true })
},
action
],
......
......@@ -514,7 +514,7 @@ export class ShowRuntimeExtensionsAction extends Action {
}
public async run(e?: any): Promise<any> {
await this._editorService.openEditor(RuntimeExtensionsInput.instance, { revealIfOpened: true });
await this._editorService.openEditor(RuntimeExtensionsInput.instance, { revealIfOpened: true, pinned: true });
}
}
......
......@@ -239,13 +239,9 @@ class ResolveSaveConflictAction extends Action {
@IEditorService private readonly editorService: IEditorService,
@INotificationService private readonly notificationService: INotificationService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IProductService private readonly productService: IProductService,
@IStorageKeysSyncRegistryService storageKeysSyncRegistryService: IStorageKeysSyncRegistryService
@IProductService private readonly productService: IProductService
) {
super('workbench.files.action.resolveConflict', nls.localize('compareChanges', "Compare"));
// opt-in to syncing
storageKeysSyncRegistryService.registerStorageKey({ key: LEARN_MORE_DIRTY_WRITE_IGNORE_KEY, version: 1 });
}
async run(): Promise<void> {
......
......@@ -472,7 +472,7 @@ export class GlobalCompareResourcesAction extends Action {
override: this.editorService.openEditor({
leftResource: activeResource,
rightResource: resource,
options: { override: false }
options: { override: false, pinned: true }
})
};
}
......@@ -482,7 +482,7 @@ export class GlobalCompareResourcesAction extends Action {
return {
override: this.editorService.openEditor({
resource: activeResource,
options: { override: false }
options: { override: false, pinned: true }
})
};
}
......@@ -828,7 +828,11 @@ export class CompareWithClipboardAction extends Action {
const name = resources.basename(resource);
const editorLabel = nls.localize('clipboardComparisonLabel', "Clipboard ↔ {0}", name);
await this.editorService.openEditor({ leftResource: resource.with({ scheme }), rightResource: resource, label: editorLabel }).finally(() => {
await this.editorService.openEditor({
leftResource: resource.with({ scheme }),
rightResource: resource, label: editorLabel,
options: { pinned: true }
}).finally(() => {
dispose(this.registrationDisposal);
this.registrationDisposal = undefined;
});
......
......@@ -136,8 +136,9 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
const resolved = await fileService.resolveAll(fileResources.map(resource => ({ resource })));
const editors = resolved.filter(r => r.stat && r.success && !r.stat.isDirectory).map(r => ({
resource: r.stat!.resource
})).concat(...untitledResources.map(untitledResource => ({ resource: untitledResource })));
resource: r.stat!.resource,
options: { pinned: true }
})).concat(...untitledResources.map(untitledResource => ({ resource: untitledResource, options: { pinned: true } })));
await editorService.openEditors(editors, SIDE_GROUP);
}
......@@ -157,7 +158,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
const resources = explorerService.getContext(true);
if (resources.length) {
await editorService.openEditors(resources.map(r => ({ resource: r.resource, options: { preserveFocus: false } })));
await editorService.openEditors(resources.map(r => ({ resource: r.resource, options: { preserveFocus: false, pinned: true } })));
}
}
});
......@@ -192,7 +193,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
const editorLabel = nls.localize('modifiedLabel', "{0} (in file) ↔ {1}", name, name);
try {
await TextFileContentProvider.open(uri, COMPARE_WITH_SAVED_SCHEMA, editorLabel, editorService);
await TextFileContentProvider.open(uri, COMPARE_WITH_SAVED_SCHEMA, editorLabel, editorService, { pinned: true });
// Dispose once no more diff editor is opened with the scheme
if (registerEditorListener) {
providerDisposables.push(editorService.onDidVisibleEditorsChange(() => {
......@@ -233,7 +234,8 @@ CommandsRegistry.registerCommand({
if (resources.length === 2) {
return editorService.openEditor({
leftResource: resources[0],
rightResource: resources[1]
rightResource: resources[1],
options: { pinned: true }
});
}
......@@ -251,7 +253,8 @@ CommandsRegistry.registerCommand({
if (globalResourceToCompare && rightResource) {
editorService.openEditor({
leftResource: globalResourceToCompare,
rightResource
rightResource,
options: { pinned: true }
});
}
}
......
......@@ -94,7 +94,7 @@ export class OpenWindowSessionLogFileAction extends Action {
placeHolder: nls.localize('log placeholder', "Select Log file")
});
if (logFileResult) {
return this.editorService.openEditor({ resource: URI.parse(logFileResult.id!) }).then(() => undefined);
return this.editorService.openEditor({ resource: URI.parse(logFileResult.id!), options: { pinned: true } }).then(() => undefined);
}
}
}
......
......@@ -200,7 +200,7 @@ registerAction2(class extends Action2 {
const instantiationService = accessor.get(IInstantiationService);
const logFileOutputChannelDescriptor = this.getLogFileOutputChannelDescriptor(outputService);
if (logFileOutputChannelDescriptor) {
await editorService.openEditor(instantiationService.createInstance(LogViewerInput, logFileOutputChannelDescriptor));
await editorService.openEditor(instantiationService.createInstance(LogViewerInput, logFileOutputChannelDescriptor), { pinned: true });
}
}
private getLogFileOutputChannelDescriptor(outputService: IOutputService): IFileOutputChannelDescriptor | null {
......@@ -298,7 +298,7 @@ registerAction2(class extends Action2 {
const entry = await quickInputService.pick(entries, { placeHolder: nls.localize('selectlogFile', "Select Log file") });
if (entry) {
assertIsDefined(entry.channel.file);
await editorService.openEditor(instantiationService.createInstance(LogViewerInput, (entry.channel as IFileOutputChannelDescriptor)));
await editorService.openEditor(instantiationService.createInstance(LogViewerInput, (entry.channel as IFileOutputChannelDescriptor)), { pinned: true });
}
}
});
......
......@@ -51,6 +51,6 @@ registerAction2(class extends Action2 {
run(accessor: ServicesAccessor) {
const editorService = accessor.get(IEditorService);
const instaService = accessor.get(IInstantiationService);
return editorService.openEditor(instaService.createInstance(PerfviewInput));
return editorService.openEditor(instaService.createInstance(PerfviewInput), { pinned: true });
}
});
......@@ -169,7 +169,8 @@ export class KeyboardLayoutPickerAction extends Action {
}
return this.editorService.openEditor({
resource: stat.resource,
mode: 'jsonc'
mode: 'jsonc',
options: { pinned: true }
});
}, (error) => {
throw new Error(nls.localize('fail.createSettings', "Unable to create '{0}' ({1}).", file.toString(), error));
......
......@@ -135,12 +135,12 @@ class HelpTreeRenderer implements ITreeRenderer<HelpModel | IHelpItem, IHelpItem
}
}
class HelpDataSource implements IAsyncDataSource<any, any> {
hasChildren(element: any) {
class HelpDataSource implements IAsyncDataSource<HelpModel, IHelpItem> {
hasChildren(element: HelpModel) {
return element instanceof HelpModel;
}
getChildren(element: any) {
getChildren(element: HelpModel) {
if (element instanceof HelpModel && element.items) {
return element.items;
}
......@@ -388,7 +388,7 @@ class IssueReporterItem extends HelpItemBase {
class HelpPanel extends ViewPane {
static readonly ID = '~remote.helpPanel';
static readonly TITLE = nls.localize('remote.help', "Help and feedback");
private tree!: WorkbenchAsyncDataTree<any, any, any>;
private tree!: WorkbenchAsyncDataTree<HelpModel, IHelpItem, IHelpItem>;
constructor(
protected viewModel: IViewModel,
......@@ -418,7 +418,7 @@ class HelpPanel extends ViewPane {
treeContainer.classList.add('remote-help-content');
container.appendChild(treeContainer);
this.tree = this.instantiationService.createInstance(WorkbenchAsyncDataTree,
this.tree = <WorkbenchAsyncDataTree<HelpModel, IHelpItem, IHelpItem>>this.instantiationService.createInstance(WorkbenchAsyncDataTree,
'RemoteHelp',
treeContainer,
new HelpTreeVirtualDelegate(),
......@@ -439,7 +439,7 @@ class HelpPanel extends ViewPane {
this.tree.setInput(model);
this._register(Event.debounce(this.tree.onDidOpen, (last, event) => event, 75, true)(e => {
e.element.handleClick();
e.element?.handleClick();
}));
}
......
......@@ -326,7 +326,7 @@ class GenerateColorThemeAction extends Action {
}, null, '\t');
contents = contents.replace(/\"__/g, '//"');
return this.editorService.openEditor({ contents, mode: 'jsonc' });
return this.editorService.openEditor({ contents, mode: 'jsonc', options: { pinned: true } });
}
}
......
......@@ -31,7 +31,7 @@ export const manageTrustedDomainSettingsCommand = {
},
handler: async (accessor: ServicesAccessor) => {
const editorService = accessor.get(IEditorService);
editorService.openEditor({ resource: TRUSTED_DOMAINS_URI, mode: 'jsonc' });
editorService.openEditor({ resource: TRUSTED_DOMAINS_URI, mode: 'jsonc', options: { pinned: true } });
return;
}
};
......@@ -117,7 +117,8 @@ export async function configureOpenerTrustedDomainsHandler(
case 'manage':
await editorService.openEditor({
resource: TRUSTED_DOMAINS_URI,
mode: 'jsonc'
mode: 'jsonc',
options: { pinned: true }
});
notificationService.prompt(Severity.Info, localize('configuringURL', "Configuring trust for: {0}", resource.toString()),
[{ label: 'Copy', run: () => clipboardService.writeText(resource.toString()) }]);
......
......@@ -42,6 +42,9 @@ export class ConfigureRuntimeArgumentsAction extends Action {
}
async run(): Promise<void> {
await this.editorService.openEditor({ resource: this.environmentService.argvResource });
await this.editorService.openEditor({
resource: this.environmentService.argvResource,
options: { pinned: true }
});
}
}
......@@ -305,7 +305,7 @@ export class ConfigurationEditingService {
}
private openFile(resource: URI): void {
this.editorService.openEditor({ resource });
this.editorService.openEditor({ resource, options: { pinned: true } });
}
private reject<T = never>(code: ConfigurationEditingErrorCode, target: EditableConfigurationTarget, operation: IConfigurationEditOperation): Promise<T> {
......
......@@ -244,7 +244,8 @@ export class BrowserHostService extends Disposable implements IHostService {
if (this.shouldReuse(options, true /* file */)) {
editorService.openEditor({
leftResource: editors[0].resource,
rightResource: editors[1].resource
rightResource: editors[1].resource,
options: { pinned: true }
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册