@@ -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
21482152function 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
0 commit comments