Support dragging block widgets into tables
Are you reporting a feature request or a bug?
Feature
Check if the issue is already reported
Nothing found
Provide detailed reproduction steps (if any)
- Open editor that has widget and table plugins enabled. e.g. http://tests.ckeditor.dev:1030/tests/plugins/widget/manual/block
- Create empty table.
- Try to drag widget into any cell.
Expected result
Widget is dragged into table cell.
Actual result
Widget is not dragged into cell.
Additional info.
It is possible to drag widget into call that contains any block element p, div, etc.
Other details
- Browser: any
Two proposed solutions:
- Introduce configuration setting
initTableWithBlock. That way people could decide whether they want to insert empty tables with emptytd'sor table withtd'scontaining paragraphs. We actually could go one step further here and let users decide which block to use. So we could have:
- config.initTableWithBlock = false; (default)
- config.initTableWithBlock = 'p' ;
- config.initTableWithBlock = 'div' ;
- config.initTableWithBlock = 'perhaps others like h1-h6' ;
- Auto-create paragraphs or divs whenever widget gets inserted. Please note that it is possible to D&D inline widget inside the table but not the block one so I'm not sure we want to cover both cases or only one that doesn't work.
There are someextra issues with widget and tables: #2189, #2190.
Has there been any progress on this?
Being able to control how these tables are generated,
or at least having some events we could tie into would be amazing.
evt.onCellAdded
ect.
Your proposed configuration solutions would be amazing
config.initTableWithBlock = 'p'
ect.
@SpencerGresoro So far we were unable to work on this issue.
As for the issue itself, it should be fixed in a way that it is possible to drop a widget directly to a table cell (even without block in it). This could be an often case that the cell has no block, and we need to handle it correctly.
Thank you mlewand, I appreciate it.
Actually this case is a bit more complicated.
Allowing dragging block widgets into table cell is simple, it can be achieved by adding
if ( el.getName() in { td: 1, th: 1 } ) {
return CKEDITOR.LINEUTILS_INSIDE;
}
At the top of: https://github.com/ckeditor/ckeditor-dev/blob/460d751f8620ab780e60756c589adfb58673a9f3/plugins/widget/plugin.js#L2582-L2617
However after doing so new issue is visible: if table has more than one column you can drag only to cells in first column. It is also visible when each table cell has <p> inside.

That's because lineutils plugin which is used to find and create line which replaces caret in drag target is designed to work only with vertical values. Two table cells in same row has same y value, hence first one will be matched as closest. Extending lineutils to work in two dimensions is beyond the scope of regular bug fix, hence I'm changing type of issue to feature request.