Repository navigation
[lexical-table][lexical-playground] Chore: Deprecate getShape() and migrate playground - #8853
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| selection.insertNodes(nodes); | ||
| } | ||
|
|
||
| // TODO Deprecate this method. It's confusing when used with colspan|rowspan |
There was a problem hiding this comment.
Wouldn't it be better to deprecate this method? It's only used once and computeSelectionCount can inline the correct version of this (and get renamed accordingly).
There was a problem hiding this comment.
I originally had this as a deprecation with the logic inlined into computeSelectionCount, but went conservative and just fixed the implementation. Should I switch the PR to deprecation + inline instead?
There was a problem hiding this comment.
I think so, reducing the API surface here (eventually) makes sense
There was a problem hiding this comment.
Done — getShape() is marked @deprecated, computeSelectionCount is renamed to $computeSelectionCounts and uses $computeTableMap + $computeTableCellRectBoundary directly. Also exported $computeTableCellRectBoundary and its TableCellRectBoundary type from @lexical/table.
| const stopY = Math.max( | ||
| anchorCellNodeRect.rowIndex + anchorCellNodeRect.rowSpan - 1, | ||
| focusCellNodeRect.rowIndex + focusCellNodeRect.rowSpan - 1, | ||
| const {anchorTable, anchorCell, focusCell} = $getCellNodes(this); |
There was a problem hiding this comment.
We can discard the changes to getShape, no need to take on the risk of this breaking someone's expectations of the old behavior. If they want it to work correctly they can get off the deprecated path.
There was a problem hiding this comment.
Reverted — getShape() now keeps the original implementation with only the @deprecated annotation added.
Description
TableSelection.getShape()only considers the colSpan/rowSpan of the anchor and focus cells, producing incorrect results when a third merged cell spans beyond the initial boundary. Rather than fix the implementation and risk breaking consumers that depend on the current behavior, this PR marksgetShape()as@deprecatedand migrates the only internal caller —computeSelectionCountinTableActionMenuPlugin— to use$computeTableMap+$computeTableCellRectBoundarydirectly (renamed to$computeSelectionCounts).$computeTableCellRectBoundaryand its return typeTableCellRectBoundaryare now exported from@lexical/table.Test plan
pnpm test-unit --project unit -- LexicalTableSelection— 14 passedgetShapebaseline: non-merged 2×2 table returns correct shape