Skip to content

Commit c4d54f9

Browse files
asdf
1 parent fe0230f commit c4d54f9

File tree

6 files changed

+30
-59
lines changed

6 files changed

+30
-59
lines changed
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
declare module "@blockly/keyboard-experiment" {
22
import { WorkspaceSvg } from "blockly";
33

4-
interface IKeyboardNavigationOptions {
5-
externalToolbox?: IExternalToolbox;
6-
}
7-
8-
interface IExternalToolbox {
9-
focus(): void;
10-
}
11-
124
class KeyboardNavigation {
13-
constructor(workspace: WorkspaceSvg, options: IKeyboardNavigationOptions)
14-
focusFlyout(): void;
15-
onExternalToolboxFocus(): void;
16-
onExternalToolboxBlur(): void;
5+
constructor(workspace: WorkspaceSvg)
176
}
187
}

pxtblocks/plugins/flyout/verticalFlyout.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export class VerticalFlyout implements Blockly.IFlyout {
2020

2121
constructor(protected options: Blockly.Options) {
2222
this.dummyWorkspace = new Blockly.WorkspaceSvg(options);
23-
this.dummyWorkspace.setVisible(false);
2423
}
2524

2625
createDom(tagName: string | Blockly.utils.Svg<SVGSVGElement> | Blockly.utils.Svg<SVGGElement>): SVGElement {
@@ -247,7 +246,7 @@ export class VerticalFlyout implements Blockly.IFlyout {
247246
}
248247
}
249248

250-
class CachedFlyout extends Blockly.VerticalFlyout {
249+
export class CachedFlyout extends Blockly.VerticalFlyout {
251250
protected def: Element[];
252251
protected buttonListeners: Blockly.browserEvents.Data[] = [];
253252

webapp/src/blocks.tsx

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,20 @@ export class Editor extends toolboxeditor.ToolboxEditor {
494494
(Blockly as any).Toolbox.prototype.position = function () {
495495
oldToolboxPosition.call(this);
496496
editor.resizeToolbox();
497-
}
497+
};
498498

499499
/**
500500
* Override blockly methods to support our custom toolbox.
501501
*/
502502
const that = this;
503+
(Blockly as any).Toolbox.prototype.updateFlyout_ = function (oldItem: Blockly.ISelectableToolboxItem | null, newItem: Blockly.ISelectableToolboxItem | null) {
504+
// Keyboard nav triggers selection on the Blockly toolbox
505+
// (first item + clear as we intercept all other events).
506+
// Hook in just to hide the flyout when selection is cleared.
507+
if (newItem === null) {
508+
that.hideFlyout();
509+
}
510+
};
503511
(Blockly.WorkspaceSvg as any).prototype.refreshToolboxSelection = function () {
504512
let ws = this.isFlyout ? this.targetWorkspace : this;
505513
if (ws && !ws.currentGesture_ && ws.toolbox_ && ws.toolbox_.flyout_) {
@@ -538,11 +546,7 @@ export class Editor extends toolboxeditor.ToolboxEditor {
538546
private initAccessibleBlocks() {
539547
const enabled = pxt.appTarget.appTheme?.accessibleBlocks;
540548
if (enabled && !this.keyboardNavigation) {
541-
this.keyboardNavigation = new KeyboardNavigation(this.editor, {
542-
externalToolbox: {
543-
focus: () => this.focusToolbox()
544-
}
545-
});
549+
this.keyboardNavigation = new KeyboardNavigation(this.editor);
546550
}
547551
}
548552

@@ -923,19 +927,27 @@ export class Editor extends toolboxeditor.ToolboxEditor {
923927

924928
public moveFocusToFlyout() {
925929
if (this.keyboardNavigation) {
926-
this.keyboardNavigation.focusFlyout();
930+
const flyout = this.editor.getFlyout()
931+
const element = ((flyout as any).svgGroup_ as SVGElement);
932+
element?.focus();
927933
}
928934
}
929935

930936
renderToolbox(immediate?: boolean) {
931937
if (pxt.shell.isReadOnly()) return;
932938
const blocklyToolboxDiv = this.getBlocklyToolboxDiv();
933939
const blocklyToolbox = <div className="blocklyToolbox">
934-
<toolbox.Toolbox ref={this.handleToolboxRef} editorname="blocks" parent={this} />
935-
{<div id="debuggerToolbox"></div>}
940+
<div className="blocklyToolboxContents" tabIndex={-1}>
941+
<toolbox.Toolbox ref={this.handleToolboxRef} editorname="blocks" parent={this} />
942+
{<div id="debuggerToolbox"></div>}
943+
</div>
936944
</div>;
937945
Util.assert(!!blocklyToolboxDiv);
938946
ReactDOM.render(blocklyToolbox, blocklyToolboxDiv);
947+
blocklyToolboxDiv.querySelector(".blocklyToolboxContents").addEventListener("focus", () => {
948+
console.log("Did it happen?");
949+
(blocklyToolboxDiv.querySelector("[role=tree]") as HTMLElement).focus()
950+
})
939951

940952
if (!immediate) this.toolbox.showLoading();
941953
}
@@ -1274,7 +1286,7 @@ export class Editor extends toolboxeditor.ToolboxEditor {
12741286
plugins: {
12751287
'blockDragger': pxtblockly.BlockDragger,
12761288
'connectionChecker': DuplicateOnDragConnectionChecker,
1277-
'flyoutsVerticalToolbox': pxtblockly.VerticalFlyout,
1289+
'flyoutsVerticalToolbox': pxtblockly.CachedFlyout,
12781290
'connectionPreviewer': pxtblockly.ConnectionPreviewer
12791291
},
12801292
move: {
@@ -1701,8 +1713,11 @@ export class Editor extends toolboxeditor.ToolboxEditor {
17011713

17021714
private showFlyoutInternal_(xmlList: Element[], flyoutName: string = "default", skipCache = false) {
17031715
this.currentFlyoutKey = flyoutName;
1704-
const flyout = this.editor.getFlyout() as pxtblockly.VerticalFlyout;
1705-
flyout.show(xmlList, skipCache ? undefined : flyoutName);
1716+
// TODO: reconsider!
1717+
// const flyout = this.editor.getFlyout() as pxtblockly.VerticalFlyout;
1718+
// flyout.show(xmlList, skipCache ? undefined : flyoutName);
1719+
const flyout = this.editor.getFlyout();
1720+
flyout.show(xmlList);
17061721
flyout.scrollToStart();
17071722
}
17081723

@@ -1953,18 +1968,7 @@ export class Editor extends toolboxeditor.ToolboxEditor {
19531968
}
19541969
}
19551970

1956-
<<<<<<< HEAD
1957-
onToolboxBlurCapture(): void {
1958-
if (this.keyboardNavigation) {
1959-
this.toolbox.clearSelection()
1960-
this.keyboardNavigation.onExternalToolboxBlur()
1961-
}
1962-
}
1963-
1964-
protected pasteCallback = () => {
1965-
=======
19661971
protected pasteCallback = (workspace: Blockly.Workspace, ev: Event) => {
1967-
>>>>>>> master
19681972
const data = getCopyData();
19691973
if (!data?.data || !this.editor || !this.canPasteData(data)) return false;
19701974

@@ -2146,7 +2150,7 @@ function fixHighlight(block: Blockly.BlockSvg) {
21462150
}
21472151

21482152
function shouldEventHideFlyout(ev: Blockly.Events.Abstract) {
2149-
if (ev.type === "var_create" || ev.type === "marker_move") {
2153+
if (ev.type === "var_create" || ev.type === "marker_move" || ev.type === "toolbox_item_select") {
21502154
return false;
21512155
}
21522156

webapp/src/monaco.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,9 +2124,6 @@ export class Editor extends toolboxeditor.ToolboxEditor {
21242124
return "";
21252125
}
21262126

2127-
onToolboxBlurCapture(): void {
2128-
// Nothing to do
2129-
}
21302127
}
21312128

21322129
export function rangeToSelection(range: monaco.IRange): monaco.Selection {

webapp/src/toolbox.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -448,18 +448,6 @@ export class Toolbox extends data.Component<ToolboxProps, ToolboxState> {
448448
this.rootElement = c;
449449
}
450450

451-
handleBlurCapture = (e: React.FocusEvent<HTMLDivElement>) => {
452-
// Make sure we close the flyout if the search input is focussed and there
453-
// is no flyout for search blocks.
454-
const searchInputEl = (this.refs.searchbox as React.Component<ToolboxSearch>).refs.searchInput;
455-
if (e.relatedTarget === searchInputEl && !this.state.hasSearch) {
456-
return this.props.parent.onToolboxBlurCapture();
457-
}
458-
if (!this.rootElement.contains(e.relatedTarget)) {
459-
this.props.parent.onToolboxBlurCapture();
460-
}
461-
}
462-
463451
handleCategoryTreeFocus = (e: React.FocusEvent<HTMLDivElement>) => {
464452
// Don't handle focus resulting from click events on category tree items.
465453
// Rely on the click handler instead.
@@ -608,7 +596,6 @@ export class Toolbox extends data.Component<ToolboxProps, ToolboxState> {
608596
ref={this.handleRootElementRef}
609597
className={classes}
610598
id={`${editorname}EditorToolbox`}
611-
onBlurCapture={this.handleBlurCapture}
612599
>
613600
<ToolboxStyle categories={this.items} />
614601
{showToolboxLabel &&

webapp/src/toolboxeditor.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ export abstract class ToolboxEditor extends srceditor.Editor {
1616
protected extensions: pxt.Package[];
1717

1818
abstract getBlocksForCategory(ns: string, subns?: string): toolbox.BlockDefinition[];
19-
/**
20-
* Hook to allow us to disable Blockly keyboard navigation when our toolbox is focussed.
21-
* Hopefully this won't be necessary when the flyout takes the focus properly.
22-
*/
23-
abstract onToolboxBlurCapture(): void;
2419

2520
protected shouldShowBlock(blockId: string, ns: string, shadow?: boolean) {
2621
let filters = this.parent.state.editorState && this.parent.state.editorState.filters;

0 commit comments

Comments
 (0)