Skip to content

Conversation

alexanderpann
Copy link
Collaborator

@alexanderpann alexanderpann commented Sep 19, 2025

Tables now support copying, cutting and deleting when multiple cells are selected with the mouse. Add the action map TableSelectionActionMap in the inspector of the table and implement the extension point TableCopyPaste to support these features for a specific table. In Addition, two new intention are available for tables that implement the extension point DataTransformation which allow parsing table data in textual form (comma- or tab-separated) and paste it to table (e.g., 10 as a number literal).

Note: This feature was initially implemented by @svott7. I moved it to MPS-Extensions and modified it a bit to be more generic.

Copy link
Collaborator

@sergej-koscejev sergej-koscejev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. CopyPasteSupport#setTable should be called setTableNode.
  2. In TableSelectionActionMap there are multiple calls to support.setTable(node) that probably can be removed (e.g. this one)
  3. TableCopyPaste: should it rather have an isApplicable(node) method than getConcept()? What if it's also applicable to subconcepts or some nodes but not others?
  4. I'm not quite sure about classloading issues with TableCopyStorage being an IDEA lightweight service. What's the benefit as opposed to having a static variable? The comment says the data will be preserved after MPS exit but I don't see how it's achieved.
  5. The storage should probably be cleared on copy-paste (including from some other application) and possibly when the nodes are unloaded? And/or it probably should store SNodeReferences rather than SNodes?
  6. TableData.iterateRowwiseWithGaps looks complicated but also unused?
  7. Can we make copy-pasting a default behavior so that action maps are only required to override it with something custom?
  8. Would it be possible to implement node-to-text transformation for copying based on editor cells' renderText() instead of node presentation? This combined with the previous point would make copy-paste work for many tables out of the box.

@alexanderpann
Copy link
Collaborator Author

  1. ✔️
  2. ✔️
  3. Also changed for DataTransformer
  4. Changed. I had issues with the tests but apparently it is now also working this way.
  5. I am clearing it now on every change of the clipboard contents. Not sure when else it should be cleared but I am storing nodes on purpose so that you could modify the nodes in the clipboard if needed (e.g. with a copy-paste handler in the future)
  6. ✔️ Removed
  7. The action map is now automatically set when no action map is used.
  8. I am now only falling back to node representation when I can't find the node cell anymore.

@alexanderpann alexanderpann force-pushed the feature/table_selection_copy_cut_paste branch from 9a5f39d to e9995b0 Compare September 24, 2025 06:25
Copy link
Collaborator

@sergej-koscejev sergej-koscejev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like UndirectedTableRangeSelection extending from TableRangeSelection. I don't see the benefits of this. I'd rather go the other way and replace it with a TableRange class that's just a rectangle.

The change from row/column start/end to two intervals is problematic because the intervals are now mutable, making the selection mutable as well, whereas it was immutable before.

Instead of passing SRepository to methods like CopyPasteSupport.paste or nodeDataToStringData let's pass EditorContext. Also perhaps we should pass EditorContext to the new isApplicable methods? And in general to all methods that may be defined by the user, such as CopyPasteSupport#copy or #delete.

DataTransformer.isApplicate → isApplicable.

I was initially skeptical about the approach with the default action map. The pattern used so far is generating calls to EditorCell.setAction if there is no action map or the action map does not have a particular action defined (example). But I think in the end the default action map is a cleaner solution so let's keep it. The linked code does not take into account action map imports, for example.

Please also update the changelog to match the current state of the changes. And instead of 'In Addition' split the entry into two for clarity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants