[Table Improvements] Insert table content#3258
Conversation
| editor.formatContentModel( | ||
| (model, context) => { | ||
| const insertPosition = deleteSelection(model, [], context).insertPoint; | ||
| const copiedModel = cloneModel(model); |
There was a problem hiding this comment.
curious why we need to clone a model?
There was a problem hiding this comment.
I used the cloned model, because it returns the content model types, not readonly types, making it easier to insert the content into the table that is ContentModelTable type.
There was a problem hiding this comment.
Could we iterate the selected blocks, mutate them and then store them in an array? If the model is very big we would need to iterate everything to clone it.
| } | ||
|
|
||
| if (path.length == 1 && block) { | ||
| table.rows[index].cells[0].blocks = [block]; |
There was a problem hiding this comment.
what if only part of a block is selected? Do we still expect to insert the whole block into table?
| } | ||
| } | ||
|
|
||
| function insertTableContent( |
There was a problem hiding this comment.
This looks more like a model API, so you can create a separate file under modelAPI folder
| /** | ||
| * @internal | ||
| */ | ||
| export function getSelectedContent( |
There was a problem hiding this comment.
This seems similar with packages\roosterjs-content-model-core\lib\command\cutCopy\getContentForCopy.ts, can you reuse?
…m/microsoft/roosterjs into u/juliaroldi/insert-table-content
| * @param model the model document | ||
| * @param selection The editor selection | ||
| * */ | ||
| export function getSelectedModel( |
There was a problem hiding this comment.
This name is confusing. Normally a function named "get**" will not modify the input object. Here it actually removes unselected contents, so better name it something like trimModelForSelection.
There was a problem hiding this comment.
And then no need to return model since we can directly get it from the parameter.
When inserting a table in a range selection, insert the selected content inside the table.
