lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Bug: Table styling not persisting for empty cells

Open ivailop7 opened this issue 1 year ago • 7 comments

Lexical version: 0.17.1

Since the table cells are empty paragraphs without text nodes, applying formatting and styling to the cells doesn't persist when text is added later. Those changes should persist irrespective if cells are empty or not. A lot of people do table changes in advance before they start entering text, will also bring behaviour inline with other editors.

https://github.com/user-attachments/assets/ad020a2c-eb23-41f7-a57e-ef4b8294610a

ivailop7 avatar Sep 01 '24 19:09 ivailop7

I think this is a design flaw, not really a bug. The workaround that is used elsewhere is to store the format on the RangeSelection, which works but that of course is ephemeral, so if you move the collapsed cursor to some text that has some existing format then the new format goes away because it was on the selection and the selection changes its format to match the existing text. This is the same way google docs works (at least with paragraphs). I think you would need to come up with some other strategy for tables (google docs persists styles on table cells or if you're at the beginning of an empty paragraph).

etrepum avatar Sep 03 '24 19:09 etrepum

It does look like there are textStyle and textFormat accessors on ParagraphNode that are currently only used by the reconciler to preserve the subtree's text style & format but that could probably be used directly by the Selection classes, at least when the ParagraphNode is empty.

etrepum avatar Sep 03 '24 20:09 etrepum

It does look like there are textStyle and textFormat accessors on ParagraphNode that are currently only used by the reconciler to preserve the subtree's text style & format but that could probably be used directly by the Selection classes, at least when the ParagraphNode is empty.

Thanks, that's how I started solving it, wanted to make sure there is no better solution.

ivailop7 avatar Sep 03 '24 20:09 ivailop7

Not that I can see! If you were trying to preserve it on the table selection it would probably be for naught because when you focus for text entry it will have been thrown away to make a RangeSelection. I have to imagine that's what this accessor is for, really, to preserve the intended format of an empty node. Whatever you do here should probably also be applied to other kinds of selection because RangeSelection also has this problem (e.g. create empty paragraph, change style on paragraph without entering text, navigate somewhere else and then back, and it's gone; or select a few empty paragraphs and then any attempt to change the format with the toolbar doesn't work even though the bold/italic buttons change their state).

etrepum avatar Sep 03 '24 20:09 etrepum

I believe that this was fixed in #6626, I can't repro

etrepum avatar Dec 02 '24 02:12 etrepum

Katsia fixed the formatting, but not styling. This one is still outstanding. Try selecting an empty table and change font size, and type in afterwards, styling doesn't persist.

ivailop7 avatar Dec 02 '24 09:12 ivailop7

The formatting is now persisting, styling (colors, font-size) is still not getting applied. Renamed the issue.

ivailop7 avatar Jan 19 '25 22:01 ivailop7