Skip to content

Incorrect tab menu position when the editors are in split mode. #295

Closed
@kittaakos

Description

@kittaakos

Originally from here:

Also, please add the following to fix the issue when there are multiple "sketch-control" toolbar items. Locating them via their ID is flawed.

Bug:
https://user-images.githubusercontent.com/1405703/113262644-21557180-92d1-11eb-9103-0ab0a16f2c78.mp4

Fix:

diff --git a/arduino-ide-extension/src/browser/contributions/sketch-control.ts b/arduino-ide-extension/src/browser/contributions/sketch-control.ts
index 6e4010c..db0aa48 100644
--- a/arduino-ide-extension/src/browser/contributions/sketch-control.ts
+++ b/arduino-ide-extension/src/browser/contributions/sketch-control.ts
@@ -6,6 +6,7 @@ import { ContextMenuRenderer } from '@theia/core/lib/browser/context-menu-render
 import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
 import { URI, SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, TabBarToolbarRegistry, open } from './contribution';
 import { ArduinoMenus } from '../menu/arduino-menus';
+import { EditorWidget } from '@theia/editor/lib/browser';
 
 @injectable()
 export class SketchControl extends SketchContribution {
@@ -24,15 +25,28 @@ export class SketchControl extends SketchContribution {
     registerCommands(registry: CommandRegistry): void {
         registry.registerCommand(SketchControl.Commands.OPEN_SKETCH_CONTROL__TOOLBAR, {
             isVisible: widget => this.shell.getWidgets('main').indexOf(widget) !== -1,
-            execute: async () => {
+            execute: async widget => {
                 this.toDisposeBeforeCreateNewContextMenu.dispose();
                 const sketch = await this.sketchServiceClient.currentSketch();
                 if (!sketch) {
                     return;
                 }
+                let target: HTMLElement | undefined = undefined;
+                if (widget instanceof EditorWidget) {
+                    const tabBar = this.shell.getTabBarFor(widget);
+                    if (tabBar) {
+                        const elements = document.querySelectorAll(`#${SketchControl.Commands.OPEN_SKETCH_CONTROL__TOOLBAR.id}`);
+                        for (const element of Array.from(elements)) {
+                            if (!target) {
+                                if (tabBar.node.contains(element)) {
+                                    target = element as HTMLElement;
+                                }
+                            }
+                        }
+                    }
+                }
 
-                const target = document.getElementById(SketchControl.Commands.OPEN_SKETCH_CONTROL__TOOLBAR.id);
-                if (!(target instanceof HTMLElement)) {
+                if (!target) {
                     return;
                 }
                 const { parentElement } = target;

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions