function registerEditorCommands(editor, playground) {
  const loadXml = () => {
    const xml = editor.getModel().getValue();
    const workspace = playground.getWorkspace();
    try {
      Blockly.Xml.clearWorkspaceAndLoadFromXml(
        Blockly.utils.xml.textToDom(xml),
        workspace,
      );
    } catch (e) {
      // If this fails that's fine.
      return false;
    }
    return true;
  };
  const loadJson = () => {
    const json = editor.getModel().getValue();
    const workspace = playground.getWorkspace();
    try {
      Blockly.serialization.workspaces.load(JSON.parse(json), workspace);
    } catch (e) {
      // If this fails that's fine.
      return false;
    }
    return true;
  };
  const save = () => {
    playground.getCurrentTab().generate();
  };

  // Add XMl Import action (only available on the XML tab).
  editor.addAction({
    id: 'import-xml',
    label: 'Import from XML',
    keybindings: [window.monaco.KeyMod.CtrlCmd | window.monaco.KeyCode.Enter],
    precondition: 'isEditorXml',
    contextMenuGroupId: 'playground',
    contextMenuOrder: 0,
    run: loadXml,
  });
  // Add XMl Export action (only available on the XML tab).
  editor.addAction({
    id: 'export-xml',
    label: 'Export to XML',
    keybindings: [window.monaco.KeyMod.CtrlCmd | window.monaco.KeyCode.KEY_S],
    precondition: 'isEditorXml',
    contextMenuGroupId: 'playground',
    contextMenuOrder: 1,
    run: save,
  });
  // Add Clean XML action (only available on the XML tab).
  editor.addAction({
    id: 'clean-xml',
    label: 'Clean XML',
    precondition: 'isEditorXml',
    contextMenuGroupId: 'playground',
    contextMenuOrder: 2,
    run: () => {
      const model = editor.getModel();
      const text = model.getValue().replace(/ (x|y|id)="[^"]*"/gim, '');
      model.pushEditOperations(
        [],
        [{range: model.getFullModelRange(), text}],
        () => null,
      );
      editor.setSelection(new window.monaco.Range(0, 0, 0, 0));
    },
  });
  // Add JSON Import action (only available on the JSON tab).
  editor.addAction({
    id: 'import-json',
    label: 'Import from JSON',
    keybindings: [window.monaco.KeyMod.CtrlCmd | window.monaco.KeyCode.Enter],
    precondition: 'isEditorJson',
    contextMenuGroupId: 'playground',
    contextMenuOrder: 0,
    run: loadJson,
  });
  // Add a Generator generate action.
  editor.addAction({
    id: 'generate',
    label: 'Generate',
    keybindings: [window.monaco.KeyMod.CtrlCmd | window.monaco.KeyCode.KEY_S],
    precondition: '!isEditorXml',
    contextMenuGroupId: 'playground',
    contextMenuOrder: 1,
    run: save,
  });
  document.addEventListener('keydown', (e) => {
    const ctrlCmd = e.metaKey || e.ctrlKey;
    if (ctrlCmd && e.key === 's') {
      save();
      e.preventDefault();
    } else if (ctrlCmd && e.key === 'Enter') {
      if (!loadJson()) loadXml();
      e.preventDefault();
    }
  });
}
Register editor commands / shortcuts.
@param {monaco.editor.IStandaloneCodeEditor} editor The monaco editor.
@param {PlaygroundAPI} playground The current playground.