Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 84109e4

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
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>
1 parent 083337d commit 84109e4

File tree

8 files changed

+217
-42
lines changed

8 files changed

+217
-42
lines changed

‎arduino-ide-extension/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"@theia/application-package": "1.25.0",
2626
"@theia/core": "1.25.0",
2727
"@theia/editor": "1.25.0",
28-
"@theia/editor-preview": "1.25.0",
2928
"@theia/electron": "1.25.0",
3029
"@theia/filesystem": "1.25.0",
3130
"@theia/keymaps": "1.25.0",
@@ -43,6 +42,7 @@
4342
"@types/auth0-js": "^9.14.0",
4443
"@types/btoa": "^1.2.3",
4544
"@types/dateformat": "^3.0.1",
45+
"@types/deep-equal": "^1.0.1",
4646
"@types/deepmerge": "^2.2.0",
4747
"@types/glob": "^7.2.0",
4848
"@types/google-protobuf": "^3.7.2",
@@ -63,6 +63,7 @@
6363
"auth0-js": "^9.14.0",
6464
"btoa": "^1.2.1",
6565
"dateformat": "^3.0.3",
66+
"deep-equal": "^2.0.5",
6667
"deepmerge": "2.0.1",
6768
"electron-updater": "^4.6.5",
6869
"fast-safe-stringify": "^2.1.1",

‎arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ import { FileNavigatorContribution as TheiaFileNavigatorContribution } from '@th
4242
import { KeymapsFrontendContribution } from './theia/keymaps/keymaps-frontend-contribution';
4343
import { KeymapsFrontendContribution as TheiaKeymapsFrontendContribution } from '@theia/keymaps/lib/browser/keymaps-frontend-contribution';
4444
import { ArduinoToolbarContribution } from './toolbar/arduino-toolbar-contribution';
45-
import { EditorPreviewContribution as TheiaEditorPreviewContribution } from '@theia/editor-preview/lib/browser/editor-preview-contribution';
46-
import { EditorPreviewContribution } from './theia/editor/editor-contribution';
45+
import { EditorContribution as TheiaEditorContribution } from '@theia/editor/lib/browser/editor-contribution';
46+
import { EditorContribution } from './theia/editor/editor-contribution';
4747
import { MonacoStatusBarContribution as TheiaMonacoStatusBarContribution } from '@theia/monaco/lib/browser/monaco-status-bar-contribution';
4848
import { MonacoStatusBarContribution } from './theia/monaco/monaco-status-bar-contribution';
4949
import {
@@ -300,6 +300,8 @@ import { WindowContribution } from './theia/core/window-contribution';
300300
import { WindowContribution as TheiaWindowContribution } from '@theia/core/lib/browser/window-contribution';
301301
import { CoreErrorHandler } from './contributions/core-error-handler';
302302
import { CompilerErrors } from './contributions/compiler-errors';
303+
import { WidgetManager } from './theia/core/widget-manager';
304+
import { WidgetManager as TheiaWidgetManager } from '@theia/core/lib/browser/widget-manager';
303305

304306
MonacoThemingService.register({
305307
id: 'arduino-theme',
@@ -509,9 +511,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
509511
rebind(TheiaKeymapsFrontendContribution)
510512
.to(KeymapsFrontendContribution)
511513
.inSingletonScope();
512-
rebind(TheiaEditorPreviewContribution)
513-
.to(EditorPreviewContribution)
514-
.inSingletonScope();
514+
rebind(TheiaEditorContribution).to(EditorContribution).inSingletonScope();
515515
rebind(TheiaMonacoStatusBarContribution)
516516
.to(MonacoStatusBarContribution)
517517
.inSingletonScope();
@@ -791,6 +791,10 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
791791
bind(DebugConfigurationManager).toSelf().inSingletonScope();
792792
rebind(TheiaDebugConfigurationManager).toService(DebugConfigurationManager);
793793

794+
// To avoid duplicate tabs use deepEqual instead of string equal: https://github.com/eclipse-theia/theia/issues/11309
795+
bind(WidgetManager).toSelf().inSingletonScope();
796+
rebind(TheiaWidgetManager).toService(WidgetManager);
797+
794798
// Preferences
795799
bindArduinoPreferences(bind);
796800

‎arduino-ide-extension/src/browser/theia/core/shell-layout-restorer.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import { notEmpty } from '@theia/core';
22
import { WidgetDescription } from '@theia/core/lib/browser';
33
import { ShellLayoutRestorer as TheiaShellLayoutRestorer } from '@theia/core/lib/browser/shell/shell-layout-restorer';
44
import { injectable } from '@theia/core/shared/inversify';
5-
import { EditorPreviewWidgetFactory } from '@theia/editor-preview/lib/browser/editor-preview-widget-factory';
65
import { EditorWidgetFactory } from '@theia/editor/lib/browser/editor-widget-factory';
76
import { FrontendApplication } from './frontend-application';
87

8+
namespace EditorPreviewWidgetFactory {
9+
export const ID = 'editor-preview-widget'; // The factory ID must be a hard-coded string because IDE2 does not depend on `@theia/editor-preview`.
10+
}
11+
912
@injectable()
1013
export class ShellLayoutRestorer extends TheiaShellLayoutRestorer {
1114
override async restoreLayout(app: FrontendApplication): Promise<boolean> {
@@ -160,8 +163,8 @@ export class ShellLayoutRestorer extends TheiaShellLayoutRestorer {
160163
constructionOptions: {
161164
factoryId: EditorWidgetFactory.ID,
162165
options: {
163-
uri,
164166
kind: 'navigatable',
167+
uri,
165168
counter: 0,
166169
},
167170
},
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import type { MaybePromise } from '@theia/core';
2+
import type { Widget } from '@theia/core/lib/browser';
3+
import { WidgetManager as TheiaWidgetManager } from '@theia/core/lib/browser/widget-manager';
4+
import { injectable } from '@theia/core/shared/inversify';
5+
import deepEqual = require('deep-equal');
6+
7+
@injectable()
8+
export class WidgetManager extends TheiaWidgetManager {
9+
/**
10+
* Customized to find any existing widget based on `options` deepEquals instead of string equals.
11+
* See https://github.com/eclipse-theia/theia/issues/11309.
12+
*/
13+
protected override doGetWidget<T extends Widget>(
14+
key: string
15+
): MaybePromise<T> | undefined {
16+
const pendingWidget = this.findExistingWidget<T>(key);
17+
if (pendingWidget) {
18+
return pendingWidget as MaybePromise<T>;
19+
}
20+
return undefined;
21+
}
22+
23+
private findExistingWidget<T extends Widget>(
24+
key: string
25+
): MaybePromise<T> | undefined {
26+
const parsed = this.parseJson(key);
27+
for (const [candidateKey, widget] of [
28+
...this.widgetPromises.entries(),
29+
...this.pendingWidgetPromises.entries(),
30+
]) {
31+
const candidate = this.parseJson(candidateKey);
32+
if (deepEqual(candidate, parsed)) {
33+
return widget as MaybePromise<T>;
34+
}
35+
}
36+
return undefined;
37+
}
38+
39+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
40+
private parseJson(json: string): any {
41+
try {
42+
return JSON.parse(json);
43+
} catch (err) {
44+
console.log(`Failed to parse JSON: <${json}>.`, err);
45+
throw err;
46+
}
47+
}
48+
}
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import { injectable } from '@theia/core/shared/inversify';
2-
import { EditorPreviewContribution as TheiaEditorPreviewContribution } from '@theia/editor-preview/lib/browser/editor-preview-contribution';
32
import { TextEditor } from '@theia/editor/lib/browser';
3+
import { EditorContribution as TheiaEditorContribution } from '@theia/editor/lib/browser/editor-contribution';
44

55
@injectable()
6-
export class EditorPreviewContribution extends TheiaEditorPreviewContribution {
7-
protected updateLanguageStatus(editor: TextEditor | undefined): void {}
8-
9-
// protected setCursorPositionStatus(editor: TextEditor | undefined): void {
10-
// if (!editor) {
11-
// this.statusBar.removeElement('editor-status-cursor-position');
12-
// return;
13-
// }
14-
// const { cursor } = editor;
15-
// this.statusBar.setElement('editor-status-cursor-position', {
16-
// text: `${cursor.line + 1}`,
17-
// alignment: StatusBarAlignment.LEFT,
18-
// priority: 100,
19-
// });
20-
// }
6+
export class EditorContribution extends TheiaEditorContribution {
7+
protected override updateLanguageStatus(
8+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-vars
9+
editor: TextEditor | undefined
10+
): void {
11+
// NOOP
12+
}
2113
}

‎browser-app/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"@theia/core": "1.25.0",
88
"@theia/debug": "1.25.0",
99
"@theia/editor": "1.25.0",
10-
"@theia/editor-preview": "1.25.0",
1110
"@theia/file-search": "1.25.0",
1211
"@theia/filesystem": "1.25.0",
1312
"@theia/keymaps": "1.25.0",

‎electron-app/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"@theia/core": "1.25.0",
99
"@theia/debug": "1.25.0",
1010
"@theia/editor": "1.25.0",
11-
"@theia/editor-preview": "1.25.0",
1211
"@theia/electron": "1.25.0",
1312
"@theia/file-search": "1.25.0",
1413
"@theia/filesystem": "1.25.0",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /