Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Cannot insert image to new inserted table row in playground #5408

Closed
tducloc opened this issue Dec 21, 2023 · 4 comments
Closed

Bug: Cannot insert image to new inserted table row in playground #5408

tducloc opened this issue Dec 21, 2023 · 4 comments
Labels
tables Relates to Lexical Tables

Comments

@tducloc
Copy link

tducloc commented Dec 21, 2023

Lexical version: 0.12.5

Steps To Reproduce

  1. Insert a table
  2. Insert a new row
  3. Insert a image on new row

Link to code example:

The current behavior

  • Console show error
Screen.Recording.2023-12-21.at.15.34.17.mov

The expected behavior

  • Should be able to insert image into table
@tducloc
Copy link
Author

tducloc commented Dec 21, 2023

By now, I temporarily fixed this by getting new inserted table row then loop through its cell and add the empty paragraph

const insertTableRowAtSelection = useCallback(
(shouldInsertAfter: boolean) => {
editor.update(() => {
$insertTableRow__EXPERIMENTAL(shouldInsertAfter);

    // get inserted table row node
    const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
    const tableRows = tableNode.getChildren();
    const tableRowIndex = shouldInsertAfter ? tableRows.length - 1 : 0;
    const tableRow = tableRows[tableRowIndex];

    // Loop through table row and insert empty paragraph nodes
    const tableCells = tableRow.getChildren();
    for (let i = 0; i < tableCells.length; i++) {
      const tableCell = tableCells[i];

      if (!$isTableCellNode(tableCell)) {
        throw new Error('Expected table cell');
      }

      tableCell.append($createParagraphNode());
    }

    clearTableSelection();
    onClose();
  });
},
[clearTableSelection, editor, onClose, tableCellNode]

);

@ivailop7 ivailop7 added the tables Relates to Lexical Tables label Dec 21, 2023
@thorn0
Copy link
Contributor

thorn0 commented Dec 22, 2023

Duplicate of #5286

@ivailop7
Copy link
Collaborator

The fix for this issue seems to be in #5912

@ivailop7
Copy link
Collaborator

ivailop7 commented Jun 9, 2024

This works now. Closing.

@ivailop7 ivailop7 closed this as completed Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tables Relates to Lexical Tables
Projects
None yet
Development

No branches or pull requests

3 participants