Skip to content

Commit 9918bc9

Browse files
committed
Added optional parameter returnCurrentIfNotFound to getEditorForBlocklyWorkspace.
1 parent 4e73234 commit 9918bc9

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

src/blocks/mrc_call_python_function.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ const CALL_PYTHON_FUNCTION = {
531531
getComponents: function(this: CallPythonFunctionBlock): storageModuleContent.Component[] {
532532
// Get the list of components whose type matches this.mrcComponentClassName.
533533
const components: storageModuleContent.Component[] = [];
534-
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace) || Editor.getCurrentEditor();
534+
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);
535535
if (editor) {
536536
let componentsToConsider: storageModuleContent.Component[] = [];
537537
if (this.mrcMechanismId) {
@@ -567,7 +567,7 @@ const CALL_PYTHON_FUNCTION = {
567567
},
568568
mrcOnLoad: function(this: CallPythonFunctionBlock): void {
569569
// mrcOnLoad is called for each CallPythonFunctionBlock when the blocks are loaded in the blockly workspace.
570-
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace) || Editor.getCurrentEditor();
570+
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);
571571
if (!editor) {
572572
return;
573573
}

src/blocks/mrc_component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const COMPONENT = {
127127
* Update the block to reflect the newly loaded extra state.
128128
*/
129129
updateBlock_: function (this: ComponentBlock): void {
130-
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace) || Editor.getCurrentEditor();
130+
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);
131131
if (editor && editor.getModuleType() === storageModule.ModuleType.ROBOT) {
132132
// Add input sockets for the arguments.
133133
for (let i = 0; i < this.mrcArgs.length; i++) {

src/blocks/mrc_event_handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const EVENT_HANDLER = {
178178
mrcOnLoad: function(this: EventHandlerBlock): void {
179179
const warnings: string[] = [];
180180

181-
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace) || Editor.getCurrentEditor();
181+
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);
182182
if (editor) {
183183
if (this.mrcSenderType === SenderType.ROBOT) {
184184
// This block is an event handler for a robot event.

src/blocks/mrc_mechanism.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const MECHANISM = {
178178
// mrcOnLoad is called for each MechanismBlock when the blocks are loaded in the blockly workspace.
179179
const warnings: string[] = [];
180180

181-
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace) || Editor.getCurrentEditor();
181+
const editor = Editor.getEditorForBlocklyWorkspace(this.workspace, true /* returnCurrentIfNotFound */);
182182
if (editor) {
183183
// Find the mechanism.
184184
let foundMechanism: storageModule.Mechanism | null = null;

src/editor/editor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ export class Editor {
498498
throw new Error('getMethodsFromMechanism: mechanism not found: ' + mechanism.className);
499499
}
500500

501-
public static getEditorForBlocklyWorkspace(workspace: Blockly.Workspace): Editor | null {
501+
public static getEditorForBlocklyWorkspace(workspace: Blockly.Workspace, opt_returnCurrentIfNotFound?: boolean): Editor | null {
502502
if (workspace.id in Editor.workspaceIdToEditor) {
503503
return Editor.workspaceIdToEditor[workspace.id];
504504
}
@@ -511,7 +511,7 @@ export class Editor {
511511
return Editor.workspaceIdToEditor[rootWorkspace.id];
512512
}
513513

514-
return null;
514+
return opt_returnCurrentIfNotFound ? Editor.currentEditor : null;
515515
}
516516

517517
public static getEditorForBlocklyWorkspaceId(workspaceId: string): Editor | null {

0 commit comments

Comments
 (0)