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

Table cell selection: support all transforms #3967

Open
Croc-ye opened this issue Jan 13, 2025 · 5 comments
Open

Table cell selection: support all transforms #3967

Croc-ye opened this issue Jan 13, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@Croc-ye
Copy link
Contributor

Croc-ye commented Jan 13, 2025

Description

企业微信截图_dede2460-2e5c-4027-b93f-cf9ddf4fbc64
企业微信截图_994da392-dea8-477a-9cf5-50d3a1164a5a

Reproduction URL

No response

Reproduction steps

1. Go to 'https://platejs.org/'
2. Click on 'Table'
3. Select multiple cells vertically to across rows.
4. set right alignment
5. error happened

Plate version

42.0.0

Slate React version

0.112.0

Screenshots

No response

Logs

No response

Browsers

Chrome

@Croc-ye Croc-ye added the bug Something isn't working label Jan 13, 2025
@Croc-ye
Copy link
Contributor Author

Croc-ye commented Jan 13, 2025

such as Numbered List, Bulleted List, Todo are the same

@Croc-ye Croc-ye closed this as completed Jan 13, 2025
@Croc-ye Croc-ye reopened this Jan 13, 2025
@zbeyens zbeyens changed the title Bug: TableComponent exception when multiple cells are selected and the right alignment is set, the unselected cells are also affected. Table cell selection: support all transforms Jan 13, 2025
@Croc-ye
Copy link
Contributor Author

Croc-ye commented Jan 13, 2025

I have a preliminary plan. Please help me see if it is feasible.

export const withAlignTable: ExtendEditor<TableConfig> = ({ editor }) => {
  const { apply } = editor;

  editor.apply = (op) => {
    if (
      op.type === 'set_node'
      // @ts-ignore
      && op?.newProperties?.align !== op.properties.align
    ) {
      // 说明 align 有变化
      const { selection } = editor;

      if (Range.isRange(selection) && hasMultiTr(editor)) {
        console.log('set_node align', op);

        const tdEntry = getAboveNode(editor, {
          at: op.path,
          match: n => isBlock(editor, n) && n.type === ELEMENT_TD,
        });
        if (tdEntry) {
          // console.log('nn @@@', nn);
          const cells = getTableGridAbove(editor, {
            at: selection!,
            format: 'cell',
          }) as TNodeEntry<TTableCellElement>[];
          const tdIdsInSelection: string[] = [];
          cells.forEach((td) => {
            td?.[0]?.id && tdIdsInSelection.push(td[0].id as string);
            // console.log('td', td);
          });
          if (!tdIdsInSelection.includes(tdEntry[0].id)) {
            console.log('not include ', tdEntry);
            return;
          }
        }
      }
    }

    apply(op);
  };

  return editor;
};

@zbeyens
Copy link
Member

zbeyens commented Jan 13, 2025

We have many transforms, I think we should override all transform methods like setNodes to be generic.

@Croc-ye
Copy link
Contributor Author

Croc-ye commented Jan 13, 2025

We have many transforms, I think we should override all transform methods like setNodes to be generic.

You are right.

@zbeyens
Copy link
Member

zbeyens commented Jan 13, 2025

This would consist of many setNodes for each selected cell path, since selecting a column does not form a single range.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants