mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-08 01:48:32 +00:00
Fixed widget lookup to eliminate duplicate tabs.
- Removed `@theia/editor-preview`, - Patched opener options when repairing layout on start, and - Compare widget keys with deepEquals instead of string equal. Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
"@theia/application-package": "1.25.0",
|
||||
"@theia/core": "1.25.0",
|
||||
"@theia/editor": "1.25.0",
|
||||
"@theia/editor-preview": "1.25.0",
|
||||
"@theia/electron": "1.25.0",
|
||||
"@theia/filesystem": "1.25.0",
|
||||
"@theia/keymaps": "1.25.0",
|
||||
@@ -43,6 +42,7 @@
|
||||
"@types/auth0-js": "^9.14.0",
|
||||
"@types/btoa": "^1.2.3",
|
||||
"@types/dateformat": "^3.0.1",
|
||||
"@types/deep-equal": "^1.0.1",
|
||||
"@types/deepmerge": "^2.2.0",
|
||||
"@types/glob": "^7.2.0",
|
||||
"@types/google-protobuf": "^3.7.2",
|
||||
@@ -63,6 +63,7 @@
|
||||
"auth0-js": "^9.14.0",
|
||||
"btoa": "^1.2.1",
|
||||
"dateformat": "^3.0.3",
|
||||
"deep-equal": "^2.0.5",
|
||||
"deepmerge": "2.0.1",
|
||||
"electron-updater": "^4.6.5",
|
||||
"fast-safe-stringify": "^2.1.1",
|
||||
|
||||
@@ -42,8 +42,8 @@ import { FileNavigatorContribution as TheiaFileNavigatorContribution } from '@th
|
||||
import { KeymapsFrontendContribution } from './theia/keymaps/keymaps-frontend-contribution';
|
||||
import { KeymapsFrontendContribution as TheiaKeymapsFrontendContribution } from '@theia/keymaps/lib/browser/keymaps-frontend-contribution';
|
||||
import { ArduinoToolbarContribution } from './toolbar/arduino-toolbar-contribution';
|
||||
import { EditorPreviewContribution as TheiaEditorPreviewContribution } from '@theia/editor-preview/lib/browser/editor-preview-contribution';
|
||||
import { EditorPreviewContribution } from './theia/editor/editor-contribution';
|
||||
import { EditorContribution as TheiaEditorContribution } from '@theia/editor/lib/browser/editor-contribution';
|
||||
import { EditorContribution } from './theia/editor/editor-contribution';
|
||||
import { MonacoStatusBarContribution as TheiaMonacoStatusBarContribution } from '@theia/monaco/lib/browser/monaco-status-bar-contribution';
|
||||
import { MonacoStatusBarContribution } from './theia/monaco/monaco-status-bar-contribution';
|
||||
import {
|
||||
@@ -300,6 +300,8 @@ import { WindowContribution } from './theia/core/window-contribution';
|
||||
import { WindowContribution as TheiaWindowContribution } from '@theia/core/lib/browser/window-contribution';
|
||||
import { CoreErrorHandler } from './contributions/core-error-handler';
|
||||
import { CompilerErrors } from './contributions/compiler-errors';
|
||||
import { WidgetManager } from './theia/core/widget-manager';
|
||||
import { WidgetManager as TheiaWidgetManager } from '@theia/core/lib/browser/widget-manager';
|
||||
|
||||
MonacoThemingService.register({
|
||||
id: 'arduino-theme',
|
||||
@@ -509,9 +511,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||
rebind(TheiaKeymapsFrontendContribution)
|
||||
.to(KeymapsFrontendContribution)
|
||||
.inSingletonScope();
|
||||
rebind(TheiaEditorPreviewContribution)
|
||||
.to(EditorPreviewContribution)
|
||||
.inSingletonScope();
|
||||
rebind(TheiaEditorContribution).to(EditorContribution).inSingletonScope();
|
||||
rebind(TheiaMonacoStatusBarContribution)
|
||||
.to(MonacoStatusBarContribution)
|
||||
.inSingletonScope();
|
||||
@@ -791,6 +791,10 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||
bind(DebugConfigurationManager).toSelf().inSingletonScope();
|
||||
rebind(TheiaDebugConfigurationManager).toService(DebugConfigurationManager);
|
||||
|
||||
// To avoid duplicate tabs use deepEqual instead of string equal: https://github.com/eclipse-theia/theia/issues/11309
|
||||
bind(WidgetManager).toSelf().inSingletonScope();
|
||||
rebind(TheiaWidgetManager).toService(WidgetManager);
|
||||
|
||||
// Preferences
|
||||
bindArduinoPreferences(bind);
|
||||
|
||||
|
||||
@@ -2,10 +2,13 @@ import { notEmpty } from '@theia/core';
|
||||
import { WidgetDescription } from '@theia/core/lib/browser';
|
||||
import { ShellLayoutRestorer as TheiaShellLayoutRestorer } from '@theia/core/lib/browser/shell/shell-layout-restorer';
|
||||
import { injectable } from '@theia/core/shared/inversify';
|
||||
import { EditorPreviewWidgetFactory } from '@theia/editor-preview/lib/browser/editor-preview-widget-factory';
|
||||
import { EditorWidgetFactory } from '@theia/editor/lib/browser/editor-widget-factory';
|
||||
import { FrontendApplication } from './frontend-application';
|
||||
|
||||
namespace EditorPreviewWidgetFactory {
|
||||
export const ID = 'editor-preview-widget'; // The factory ID must be a hard-coded string because IDE2 does not depend on `@theia/editor-preview`.
|
||||
}
|
||||
|
||||
@injectable()
|
||||
export class ShellLayoutRestorer extends TheiaShellLayoutRestorer {
|
||||
override async restoreLayout(app: FrontendApplication): Promise<boolean> {
|
||||
@@ -160,8 +163,8 @@ export class ShellLayoutRestorer extends TheiaShellLayoutRestorer {
|
||||
constructionOptions: {
|
||||
factoryId: EditorWidgetFactory.ID,
|
||||
options: {
|
||||
uri,
|
||||
kind: 'navigatable',
|
||||
uri,
|
||||
counter: 0,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import type { MaybePromise } from '@theia/core';
|
||||
import type { Widget } from '@theia/core/lib/browser';
|
||||
import { WidgetManager as TheiaWidgetManager } from '@theia/core/lib/browser/widget-manager';
|
||||
import { injectable } from '@theia/core/shared/inversify';
|
||||
import deepEqual = require('deep-equal');
|
||||
|
||||
@injectable()
|
||||
export class WidgetManager extends TheiaWidgetManager {
|
||||
/**
|
||||
* Customized to find any existing widget based on `options` deepEquals instead of string equals.
|
||||
* See https://github.com/eclipse-theia/theia/issues/11309.
|
||||
*/
|
||||
protected override doGetWidget<T extends Widget>(
|
||||
key: string
|
||||
): MaybePromise<T> | undefined {
|
||||
const pendingWidget = this.findExistingWidget<T>(key);
|
||||
if (pendingWidget) {
|
||||
return pendingWidget as MaybePromise<T>;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private findExistingWidget<T extends Widget>(
|
||||
key: string
|
||||
): MaybePromise<T> | undefined {
|
||||
const parsed = this.parseJson(key);
|
||||
for (const [candidateKey, widget] of [
|
||||
...this.widgetPromises.entries(),
|
||||
...this.pendingWidgetPromises.entries(),
|
||||
]) {
|
||||
const candidate = this.parseJson(candidateKey);
|
||||
if (deepEqual(candidate, parsed)) {
|
||||
return widget as MaybePromise<T>;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
private parseJson(json: string): any {
|
||||
try {
|
||||
return JSON.parse(json);
|
||||
} catch (err) {
|
||||
console.log(`Failed to parse JSON: <${json}>.`, err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,13 @@
|
||||
import { injectable } from '@theia/core/shared/inversify';
|
||||
import { EditorPreviewContribution as TheiaEditorPreviewContribution } from '@theia/editor-preview/lib/browser/editor-preview-contribution';
|
||||
import { TextEditor } from '@theia/editor/lib/browser';
|
||||
import { EditorContribution as TheiaEditorContribution } from '@theia/editor/lib/browser/editor-contribution';
|
||||
|
||||
@injectable()
|
||||
export class EditorPreviewContribution extends TheiaEditorPreviewContribution {
|
||||
protected updateLanguageStatus(editor: TextEditor | undefined): void {}
|
||||
|
||||
// protected setCursorPositionStatus(editor: TextEditor | undefined): void {
|
||||
// if (!editor) {
|
||||
// this.statusBar.removeElement('editor-status-cursor-position');
|
||||
// return;
|
||||
// }
|
||||
// const { cursor } = editor;
|
||||
// this.statusBar.setElement('editor-status-cursor-position', {
|
||||
// text: `${cursor.line + 1}`,
|
||||
// alignment: StatusBarAlignment.LEFT,
|
||||
// priority: 100,
|
||||
// });
|
||||
// }
|
||||
export class EditorContribution extends TheiaEditorContribution {
|
||||
protected override updateLanguageStatus(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-vars
|
||||
editor: TextEditor | undefined
|
||||
): void {
|
||||
// NOOP
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user