Tab order in editor [MPS 3.0)]

Is it possible to change the tab order in which the user goes through an editor?  I am using mathematical formulas and would like the order to start with the lowerbound, then the upperbound and then the body.
9 comments
There is no build in functionality for that.
You can add action maps to the editor cells and change the NEXT (tab) and PREV (shift+tab) actions. To select a specific property you can use
node.select[in: editorContext, cell: {name}];
prettyPrint();
0
Nice workaround,it seems to work ok. Thanks.
The only problem I have left is how I can specify which editor element gets the focus both on creation, and also whenever the user tabs into the concept.
0
You can set attracts focus to attractsFocus of the cell that should get the focus when the node is created.

Changing the target, when the user tabs into the concept is a bit more difficult. Action events are passed up the editor cells tree to the first cell that has a handler for it. If you don't have a root concept where you can handle the events, the remaining option is to override the keymap of MPS and handle the TAB keyboard event directly:
  1. Add a plugin aspect to your language
  2. Create root nodes of type j.m.l.plugin.standalone.StandalonePluginDescriptor, j.m.l.plugin.KeymapChangesDeclaration and j.m.l.plugin.ActionDeclaration
  3. I have not tested it, but the ActionDeclaration should look like this
    action FocusNext {
      action context parameters ( always visible = false )
        EditorComponent editorComponent key: EDITOR_COMPONENT required
    
      isApplicable(event)->boolean {
      if (!(this.editorComponent.isFocusOwner()) || this.editorComponent.getNodeSubstituteChooser().isVisible()) { return false; }
      EditorCellLabelSelection selection = this.editorComponent.getSelectionManager().getSelection() as EditorCellLabelSelection;
      if (selection == null) { return false; }
      EditorCell currentCell = selection.getEditorCell();
      EditorCell nextCell = CellTraversalUtil.getNextLeaf(currentCell, CellConditions.SELECTABLE);
      node<> currentNode = currentCell.?getSNode();
      node<> nextNode = nextCell.?getSNode();
      if (!(currentNode.isInstanceOf(MyConcept)) && nextNode.isInstanceOf(MyConcept)) {
        return true;
      }
      return false;
    }
    
      execute(event)->void {
      EditorCellLabelSelection selection = this.editorComponent.getSelectionManager().getSelection() as EditorCellLabelSelection;
      if (selection == null) { return; }
      EditorCell currentCell = selection.getEditorCell();
      EditorCell nextCell = CellTraversalUtil.getNextLeaf(currentCell, CellConditions.SELECTABLE);
      node<MyConcept> nextNode = nextCell.getSNode() : MyConcept;
      nextNode.select[in: this.editorComponent.getEditorContext(), cell: {name}];
    }
    }      
    
    prettyPrint();
  4. In the keymap simply add the action and use the keycode VK_TAB
0
I already tried to set "attractsFocus" on the cell that I want to have focus first, but nothing happens. All other elements have "noAttraction" set. However, the focus is still on the first element in the editor.
0
Try to set attractsRecursively on the root cell of your concept.
0
Hi

I am interested in trying some Java extensions in MPS, but I want to extend Java only - extending Base Language is of no interest to me, and I explicitly must not have any of its extensions. This is, amongst other reasons, so that existing Java codebases can be used directly with any extensions of mine, without any conversion.
0
Abeeha,  I think you posted to the wrong thread.
0
Sascha, I tried many combinations of attacts focus and attracts recursively,  but noine of them seem to make any difference.
0
If you prepare a sample project, I can try to find a working solution.
0

Please sign in to leave a comment.