JetBrains / MPS-extensions

MPS-extensions aims to ease language development within MPS.
https://jetbrains.github.io/MPS-extensions/
Apache License 2.0
82 stars 50 forks source link

Table: Cell selection changes unexpectedly #167

Open digital-ember opened 5 years ago

digital-ember commented 5 years ago

Imagine the following structure:

concept Table 
  rows : Row [0..n]

concept Row
  cells : Cell [0..n]

concept Cell
  value : string

and an instance like so, using slisson.Table as Editor: image

Having the cursor within a value cell, pressing CTRL+UP once selects the complete cell property, as expected:

image

Pressing CTRL+UP once more, selects the Grid_Cell representing the node of concept "Cell", but as node context (see inspector), it holds the node of concept Table, which we consider unexpected:

image

Pressing CTRL+UP once more, the node of concept Row is considered the node context.

image

This is bad for invoking actions / intentions in the context where the complete Table is the node context, whilst the editor suggests the cell is selected.

digital-ember commented 5 years ago

Here is a SSCCE for reference: AttributeInTable.zip

alexanderpann commented 7 months ago

We can't change the behavior as it would be breaking but there is a workaround that we also added in another project. Surround the table with a custom factory cell from de.slisson.mps.richtext.customcell and add the following content:

TreeIterator<EditorCell> iterator = CellTraversalUtil.iterateTree(cell, cell, true).iterator(); 
while (iterator.hasNext()) { 
 EditorCell nextCell = iterator.next(); 
 if (nextCell instanceof EditorCell_GridCell) { 
   nextCell.getStyle().set(StyleAttributes.SELECTABLE, false); 
 } 
} 
cell;

We could add a flag to the table editor to allow switching to this behavior.