@@ -181,9 +181,7 @@ export async function setCurrentCursorNodeById(
181181 const workspaceSvg = Blockly . getMainWorkspace ( ) as Blockly . WorkspaceSvg ;
182182 const rootBlock = workspaceSvg . getBlockById ( blockId ) ;
183183 if ( rootBlock ) {
184- workspaceSvg
185- . getCursor ( )
186- ?. setCurNode ( Blockly . ASTNode . createBlockNode ( rootBlock ) ) ;
184+ workspaceSvg . getCursor ( ) ?. setCurNode ( rootBlock ) ;
187185 }
188186 } , blockId ) ;
189187}
@@ -199,7 +197,7 @@ export async function getCurrentCursorNodeId(
199197) : Promise < string | undefined > {
200198 return await browser . execute ( ( ) => {
201199 const workspaceSvg = Blockly . getMainWorkspace ( ) as Blockly . WorkspaceSvg ;
202- return workspaceSvg . getCursor ( ) ?. getCurNode ( ) ?. getSourceBlock ( ) ?. id ;
200+ return workspaceSvg . getCursor ( ) ?. getSourceBlock ( ) ?. id ;
203201 } ) ;
204202}
205203
@@ -214,7 +212,28 @@ export async function getCurrentCursorNodeType(
214212) : Promise < string | undefined > {
215213 return await browser . execute ( ( ) => {
216214 const workspaceSvg = Blockly . getMainWorkspace ( ) as Blockly . WorkspaceSvg ;
217- return workspaceSvg . getCursor ( ) ?. getCurNode ( ) ?. getType ( ) ;
215+ const node = workspaceSvg . getCursor ( ) ?. getCurNode ( ) ;
216+ if ( node instanceof Blockly . WorkspaceSvg ) {
217+ return 'workspace' ;
218+ } else if ( node instanceof Blockly . BlockSvg ) {
219+ return 'block' ;
220+ } else if ( node instanceof Blockly . Field ) {
221+ return 'field' ;
222+ } else if ( node instanceof Blockly . FlyoutButton ) {
223+ return 'button' ;
224+ } else if ( node instanceof Blockly . RenderedConnection ) {
225+ if ( node . getParentInput ( ) ) {
226+ return 'input' ;
227+ }
228+
229+ if ( node . type === Blockly . ConnectionType . OUTPUT_VALUE ) {
230+ return 'output' ;
231+ } else if ( node . type === Blockly . ConnectionType . NEXT_STATEMENT ) {
232+ return 'next' ;
233+ } else if ( node . type === Blockly . ConnectionType . PREVIOUS_STATEMENT ) {
234+ return 'previous' ;
235+ }
236+ }
218237 } ) ;
219238}
220239
@@ -229,10 +248,7 @@ export async function getCurrentCursorNodeFieldName(
229248) : Promise < string | undefined > {
230249 return await browser . execute ( ( ) => {
231250 const workspaceSvg = Blockly . getMainWorkspace ( ) as Blockly . WorkspaceSvg ;
232- const field = workspaceSvg
233- . getCursor ( )
234- ?. getCurNode ( )
235- ?. getLocation ( ) as Blockly . Field ;
251+ const field = workspaceSvg . getCursor ( ) ?. getCurNode ( ) as Blockly . Field ;
236252 return field . name ;
237253 } ) ;
238254}
0 commit comments