Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement workbench.editor.revealIfOpen preference #12145

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions packages/core/src/browser/core-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { isOSX } from '../common/os';
import { nls } from '../common/nls';
import { DefaultTheme } from '@theia/application-package/lib/application-props';

/* eslint-disable max-len */
const windowTitleDescription = [
'Controls the window title based on the active editor. Variables are substituted based on the context:',
'`${activeEditorShort}`: the file name (e.g. myFile.txt).',
Expand Down Expand Up @@ -52,7 +53,6 @@ export const corePreferenceSchema: PreferenceSchema = {
'always',
],
default: 'ifRequired',
// eslint-disable-next-line max-len
description: nls.localizeByDefault('Controls whether to show a confirmation dialog before closing the browser tab or window. Note that even if enabled, browsers may still decide to close a tab or window without confirmation and that this setting is only a hint that may not work in all cases.'),
},
'breadcrumbs.enabled': {
Expand Down Expand Up @@ -91,7 +91,6 @@ export const corePreferenceSchema: PreferenceSchema = {
],
default: 'classic',
scope: 'application',
// eslint-disable-next-line max-len
markdownDescription: nls.localizeByDefault("Control the visibility of the menu bar. A setting of 'toggle' means that the menu bar is hidden and a single press of the Alt key will show it. A setting of 'compact' will move the menu into the side bar."),
included: !(isOSX && environment.electron.is())
},
Expand All @@ -112,7 +111,6 @@ export const corePreferenceSchema: PreferenceSchema = {
'http.proxy': {
type: 'string',
pattern: '^https?://([^:]*(:[^@]*)?@)?([^:]+|\\[[:0-9a-fA-F]+\\])(:\\d+)?/?$|^$',
// eslint-disable-next-line max-len
markdownDescription: nls.localizeByDefault('The proxy setting to use. If not set, will be inherited from the `http_proxy` and `https_proxy` environment variables.'),
scope: 'application'
},
Expand Down Expand Up @@ -143,7 +141,6 @@ export const corePreferenceSchema: PreferenceSchema = {
'http.systemCertificates': {
type: 'boolean',
default: true,
// eslint-disable-next-line max-len
description: nls.localizeByDefault('Controls whether CA certificates should be loaded from the OS. (On Windows and macOS, a reload of the window is required after turning this off.)'),
scope: 'application'
},
Expand All @@ -154,18 +151,15 @@ export const corePreferenceSchema: PreferenceSchema = {
'doubleClick'
],
default: 'singleClick',
// eslint-disable-next-line max-len
description: nls.localizeByDefault('Controls how to open items in trees and lists using the mouse (if supported). Note that some trees and lists might choose to ignore this setting if it is not applicable.')
},
'workbench.editor.highlightModifiedTabs': {
'type': 'boolean',
// eslint-disable-next-line max-len
'markdownDescription': nls.localize('theia/core/highlightModifiedTabs', 'Controls whether a top border is drawn on modified (dirty) editor tabs or not.'),
'default': false
},
'workbench.editor.closeOnFileDelete': {
'type': 'boolean',
// eslint-disable-next-line max-len
'description': nls.localizeByDefault('Controls whether editors showing a file that was opened during the session should close automatically when getting deleted or renamed by some other process. Disabling this will keep the editor open on such an event. Note that deleting from within the application will always close the editor and that editors with unsaved changes will never close to preserve your data.'),
'default': false
},
Expand All @@ -174,11 +168,15 @@ export const corePreferenceSchema: PreferenceSchema = {
'description': nls.localizeByDefault("Enables the use of mouse buttons four and five for commands 'Go Back' and 'Go Forward'."),
'default': true
},
'workbench.editor.revealIfOpen': {
'type': 'boolean',
'description': nls.localizeByDefault('Controls whether an editor is revealed in any of the visible groups if opened. If disabled, an editor will prefer to open in the currently active editor group. If enabled, an already opened editor will be revealed instead of opened again in the currently active editor group. Note that there are some cases where this setting is ignored, e.g. when forcing an editor to open in a specific group or to the side of the currently active group.'),
'default': false
},
'workbench.commandPalette.history': {
type: 'number',
default: 50,
minimum: 0,
// eslint-disable-next-line max-len
description: nls.localizeByDefault('Controls the number of recently used commands to keep in history for the command palette. Set to 0 to disable command history.')
},
'workbench.colorTheme': {
Expand Down Expand Up @@ -228,7 +226,6 @@ export const corePreferenceSchema: PreferenceSchema = {
default: 4,
minimum: 1,
maximum: 20,
// eslint-disable-next-line max-len
description: nls.localizeByDefault('Controls the feedback area size in pixels of the dragging area in between views/editors. Set it to a larger value if you feel it\'s hard to resize views using the mouse.')
},
'workbench.tab.maximize': {
Expand All @@ -252,6 +249,7 @@ export interface CoreConfiguration {
'workbench.editor.highlightModifiedTabs': boolean;
'workbench.editor.mouseBackForwardToNavigate': boolean;
'workbench.editor.closeOnFileDelete': boolean;
'workbench.editor.revealIfOpen': boolean;
'workbench.colorTheme': string;
'workbench.iconTheme': string;
'workbench.silentNotifications': boolean;
Expand Down
11 changes: 10 additions & 1 deletion packages/editor/src/browser/editor-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { injectable, postConstruct, inject } from '@theia/core/shared/inversify';
import URI from '@theia/core/lib/common/uri';
import { RecursivePartial, Emitter, Event, MaybePromise } from '@theia/core/lib/common';
import { WidgetOpenerOptions, NavigatableWidgetOpenHandler, NavigatableWidgetOptions, Widget } from '@theia/core/lib/browser';
import { WidgetOpenerOptions, NavigatableWidgetOpenHandler, NavigatableWidgetOptions, Widget, PreferenceService } from '@theia/core/lib/browser';
import { EditorWidget } from './editor-widget';
import { Range, Position, Location, TextEditor } from './editor';
import { EditorWidgetFactory } from './editor-widget-factory';
Expand Down Expand Up @@ -54,6 +54,8 @@ export class EditorManager extends NavigatableWidgetOpenHandler<EditorWidget> {
*/
readonly onCurrentEditorChanged: Event<EditorWidget | undefined> = this.onCurrentEditorChangedEmitter.event;

@inject(PreferenceService) protected readonly preferenceService: PreferenceService;

@postConstruct()
protected override init(): void {
super.init();
Expand Down Expand Up @@ -205,6 +207,13 @@ export class EditorManager extends NavigatableWidgetOpenHandler<EditorWidget> {
}
}
}
// If the user has opted to prefer to open an existing editor even if it's on a different tab, check if we have anything about the URI.
if (this.preferenceService.get('workbench.editor.revealIfOpen', false)) {
const counter = this.getCounterForUri(uri);
if (counter !== undefined) {
return super.open(uri, { counter, ...options });
}
}
// Open a new widget.
return super.open(uri, { counter: this.createCounterForUri(uri), ...options });
}
Expand Down