Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
55 changes: 39 additions & 16 deletions src/actions/arrow_navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {ASTNode, ShortcutRegistry, utils as BlocklyUtils} from 'blockly/core';

import type {Field, Toolbox, WorkspaceSvg} from 'blockly/core';

import * as Blockly from 'blockly/core';
import * as Constants from '../constants';
import type {Navigation} from '../navigation';

Expand Down Expand Up @@ -53,6 +54,7 @@ export class ArrowNavigation {
shortcut: ShortcutRegistry.KeyboardShortcut,
): boolean => {
const toolbox = workspace.getToolbox() as Toolbox;
const flyout = workspace.getFlyout();
let isHandled = false;
switch (this.navigation.getState(workspace)) {
case Constants.STATE.WORKSPACE:
Expand All @@ -67,12 +69,11 @@ export class ArrowNavigation {
}
return isHandled;
case Constants.STATE.TOOLBOX:
isHandled =
toolbox && typeof toolbox.onShortcut === 'function'
? toolbox.onShortcut(shortcut)
: false;
if (!isHandled) {
this.navigation.focusFlyout(workspace);
// @ts-expect-error private method
isHandled = toolbox && toolbox.selectChild();
if (!isHandled && flyout) {
Blockly.getFocusManager().focusTree(flyout.getWorkspace());
this.navigation.defaultFlyoutCursorIfNeeded(workspace);
}
return true;
default:
Expand Down Expand Up @@ -100,12 +101,13 @@ export class ArrowNavigation {
}
return isHandled;
case Constants.STATE.FLYOUT:
this.navigation.focusToolbox(workspace);
if (toolbox) {
Blockly.getFocusManager().focusTree(toolbox);
}
return true;
case Constants.STATE.TOOLBOX:
return toolbox && typeof toolbox.onShortcut === 'function'
? toolbox.onShortcut(shortcut)
: false;
// @ts-expect-error private method
return toolbox && toolbox.selectParent();
default:
return false;
}
Expand Down Expand Up @@ -173,9 +175,24 @@ export class ArrowNavigation {
}
return isHandled;
case Constants.STATE.TOOLBOX:
return toolbox && typeof toolbox.onShortcut === 'function'
? toolbox.onShortcut(shortcut)
: false;
if (toolbox) {
if (!toolbox.getSelectedItem()) {
const firstItem =
toolbox
.getToolboxItems()
.find((item) => item.isSelectable()) ?? null;
toolbox.setSelectedItem(firstItem);
isHandled = true;
} else {
// @ts-expect-error private method
isHandled = toolbox.selectNext();
}
const selectedItem = toolbox.getSelectedItem();
if (selectedItem) {
Blockly.getFocusManager().focusNode(selectedItem);
}
}
return isHandled;
default:
return false;
}
Expand Down Expand Up @@ -221,9 +238,15 @@ export class ArrowNavigation {
}
return isHandled;
case Constants.STATE.TOOLBOX:
return toolbox && typeof toolbox.onShortcut === 'function'
? toolbox.onShortcut(shortcut)
: false;
if (toolbox) {
// @ts-expect-error private method
isHandled = toolbox.selectPrevious();
const selectedItem = toolbox.getSelectedItem();
if (selectedItem) {
Blockly.getFocusManager().focusNode(selectedItem);
}
}
return isHandled;
default:
return false;
}
Expand Down
11 changes: 6 additions & 5 deletions src/actions/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
clipboard,
ICopyData,
LineCursor,
getFocusManager,
} from 'blockly';
import * as Constants from '../constants';
import type {BlockSvg, WorkspaceSvg} from 'blockly';
Expand Down Expand Up @@ -281,7 +282,7 @@ export class Clipboard {
const copied = !!this.copyData;
if (copied) {
if (navigationState === Constants.STATE.FLYOUT) {
this.navigation.focusWorkspace(workspace);
getFocusManager().focusTree(workspace);
}
showCopiedHint(workspace);
}
Expand Down Expand Up @@ -375,10 +376,10 @@ export class Clipboard {
? workspace
: this.copyWorkspace;

const targetNode = this.navigation.getStationaryNode(pasteWorkspace);
// If we're pasting in the flyout it still targets the workspace. Focus first
// so ensure correct selection handling.
this.navigation.focusWorkspace(workspace);
const targetNode = this.navigation.getFocusedASTNode(pasteWorkspace);
// If we're pasting in the flyout it still targets the workspace. Focus
// first as to ensure correct selection handling.
getFocusManager().focusTree(workspace);

Events.setGroup(true);
const block = clipboard.paste(this.copyData, pasteWorkspace) as BlockSvg;
Expand Down
8 changes: 3 additions & 5 deletions src/actions/enter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ import {
Events,
ShortcutRegistry,
utils as BlocklyUtils,
} from 'blockly/core';

import type {
Block,
BlockSvg,
Field,
FlyoutButton,
WorkspaceSvg,
getFocusManager,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not need to change all of the import types to imports just to add the focus manager.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I think I missed the type specifier and thought there were redundant import lines (which, in retrospect, I now realize would've been caught by the linter). Fixed in latest.

} from 'blockly/core';

import * as Constants from '../constants';
Expand Down Expand Up @@ -134,7 +132,7 @@ export class EnterAction {
Events.setGroup(true);
}

const stationaryNode = this.navigation.getStationaryNode(workspace);
const stationaryNode = this.navigation.getFocusedASTNode(workspace);
const newBlock = this.createNewBlock(workspace);
if (!newBlock) return;
const insertStartPoint = stationaryNode
Expand All @@ -146,7 +144,7 @@ export class EnterAction {

workspace.setResizesEnabled(true);

this.navigation.focusWorkspace(workspace);
getFocusManager().focusTree(workspace);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
workspace.getCursor()?.setCurNode(ASTNode.createBlockNode(newBlock)!);
this.mover.startMove(workspace, newBlock, insertStartPoint);
Expand Down
12 changes: 10 additions & 2 deletions src/actions/exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {ShortcutRegistry, utils as BlocklyUtils} from 'blockly/core';
import {
ShortcutRegistry,
utils as BlocklyUtils,
getFocusManager,
Gesture,
} from 'blockly/core';

import * as Constants from '../constants';
import type {Navigation} from '../navigation';
Expand All @@ -29,7 +34,10 @@ export class ExitAction {
switch (this.navigation.getState(workspace)) {
case Constants.STATE.FLYOUT:
case Constants.STATE.TOOLBOX:
this.navigation.focusWorkspace(workspace);
getFocusManager().focusTree(workspace);
if (!Gesture.inProgress()) {
workspace.hideChaff();
}
return true;
default:
return false;
Expand Down
8 changes: 8 additions & 0 deletions src/actions/mover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ASTNode,
Connection,
dragging,
getFocusManager,
registry,
utils,
WorkspaceSvg,
Expand Down Expand Up @@ -132,6 +133,9 @@ export class Mover {
// Begin drag.
dragger.onDragStart(info.fakePointerEvent('pointerdown'));
info.updateTotalDelta();
// In case the block is detached, ensure that it still retains focus
// (otherwise dragging will break).
getFocusManager().focusNode(block);
return true;
}

Expand Down Expand Up @@ -159,6 +163,8 @@ export class Mover {
this.moves.delete(workspace);
// Delay scroll until after block has finished moving.
setTimeout(() => this.scrollCurrentBlockIntoView(workspace), 0);
// If the block gets reattached, ensure it retains focus.
getFocusManager().focusNode(info.block);
return true;
}

Expand Down Expand Up @@ -205,6 +211,8 @@ export class Mover {
this.moves.delete(workspace);
// Delay scroll until after block has finished moving.
setTimeout(() => this.scrollCurrentBlockIntoView(workspace), 0);
// If the block gets reattached, ensure it retains focus.
getFocusManager().focusNode(info.block);
return true;
}

Expand Down
32 changes: 0 additions & 32 deletions src/gesture_monkey_patch.js

This file was deleted.

Loading
Loading