mit-cml / workspace-multiselect

A Blockly plugin that allows you to drag, select and manipulate multiple blocks in the workspace.
https://hollowman6.github.io/workspace-multiselect/multi-workspace
11 stars 12 forks source link

Unexpected focus is claimed on mouse enter of the workspace div #40

Closed koenvanwijk closed 6 months ago

koenvanwijk commented 6 months ago

The following code claims focus when the mouse enters the workspace div:

 injectionDiv.addEventListener('mouseenter', () => {
      if (document.activeElement === this.workspace_.svgGroup_.parentElement ||
          document.activeElement.nodeName.toLowerCase() === 'input' ||
          document.activeElement.nodeName.toLowerCase() === 'textarea') {
        return;
      }
      this.workspace_.svgGroup_.parentElement.focus();
    });

As shown some exceptions are made on 'input' and 'textarea' however in my case another node type that is closed due to the change of focus.

What functionality will break when this code is removed? It is probably not a good idea to extend the list of exceptions...

As shown in the video below a vscode menu is closed as the focus is set to the workspace div when I enter the div.

https://github.com/mit-cml/workspace-multiselect/assets/8227977/9c3eb76d-95e5-4cd6-99f9-85966a81ff2e

HollowMan6 commented 6 months ago

It's interesting to see you integrate Blockly into VSCode somehow. We can add a configuration to disable the workspace auto-focus, as it looks like it's the only feasible way to fix it here. That feature was designed to remove the need to click (focus) the workspace for multi-selection when we have multiple workspaces (#19), so it can be more straightforward to switch between workspaces, so it shouldn't break something when you only have one workspace.

HollowMan6 commented 6 months ago

The fix will be landed in v0.1.12: https://github.com/HollowMan6/workspace-multiselect/commit/743d1d43f45fd2e9ae8c497a93875f1a48c05ac8

Note that if you get the workspace autofocus disabled and still want to get the workspace focused after the page load, you can try this code: https://github.com/mit-cml/workspace-multiselect/pull/19/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L61-L64

koenvanwijk commented 6 months ago

Sounds like a good solution, thanks for the quick fix!