From 75539311543f3ffaa7e6c81c277238da32730e0f Mon Sep 17 00:00:00 2001 From: Ivaylo Pavlov Date: Sat, 31 Aug 2024 18:20:48 +0300 Subject: [PATCH 1/2] Fix table cell format for single cell --- .../src/LexicalTableSelectionHelpers.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/lexical-table/src/LexicalTableSelectionHelpers.ts b/packages/lexical-table/src/LexicalTableSelectionHelpers.ts index a543979644c..f5cb9dc7561 100644 --- a/packages/lexical-table/src/LexicalTableSelectionHelpers.ts +++ b/packages/lexical-table/src/LexicalTableSelectionHelpers.ts @@ -459,6 +459,21 @@ export function applyTableHandlers( FORMAT_ELEMENT_COMMAND, (formatType) => { const selection = $getSelection(); + if ( + $isSelectionInTable(selection, tableNode) && + selection!.getNodes().length === 1 && + $isTextNode(selection!.getNodes()[0]) + ) { + const tableCellNode = $findMatchingParent( + selection!.getNodes()[0], + $isTableCellNode, + ); + if (tableCellNode) { + tableCellNode.setFormat(formatType); + } + return false; + } + if ( !$isTableSelection(selection) || !$isSelectionInTable(selection, tableNode) From 0d2147a5099645f87f5024ec907327b220435756 Mon Sep 17 00:00:00 2001 From: Ivaylo Pavlov Date: Sun, 1 Sep 2024 20:43:11 +0300 Subject: [PATCH 2/2] support node selection alignment inside table cell --- .../src/LexicalTableSelectionHelpers.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/lexical-table/src/LexicalTableSelectionHelpers.ts b/packages/lexical-table/src/LexicalTableSelectionHelpers.ts index f5cb9dc7561..3ee9bb719aa 100644 --- a/packages/lexical-table/src/LexicalTableSelectionHelpers.ts +++ b/packages/lexical-table/src/LexicalTableSelectionHelpers.ts @@ -38,6 +38,7 @@ import { $getSelection, $isDecoratorNode, $isElementNode, + $isNodeSelection, $isRangeSelection, $isRootOrShadowRoot, $isTextNode, @@ -460,17 +461,15 @@ export function applyTableHandlers( (formatType) => { const selection = $getSelection(); if ( - $isSelectionInTable(selection, tableNode) && - selection!.getNodes().length === 1 && - $isTextNode(selection!.getNodes()[0]) + $isSelectionInTable(selection, tableNode) || + $isNodeSelection(selection) ) { - const tableCellNode = $findMatchingParent( - selection!.getNodes()[0], - $isTableCellNode, - ); - if (tableCellNode) { - tableCellNode.setFormat(formatType); - } + selection!.getNodes().forEach((node) => { + const tableCellNode = $findMatchingParent(node, $isTableCellNode); + if (tableCellNode) { + tableCellNode.setFormat(formatType); + } + }); return false; }