plate
plate copied to clipboard
Alignment Issue : When whole text is selected it always shows left aligned
Description
Alignment Issue : When whole text is selected it always shows left aligned
Steps to Reproduce
go to https://platejs.org/ and try selecting whole sentence which is center aligned and when you select all it shows left aligned
https://github.com/udecode/plate/assets/66991625/599a1d9d-0f1f-420b-aeb9-dbe951a7e6af
Funding
- You can sponsor this specific effort via a Polar.sh pledge below
- We receive the pledge once the issue is completed & verified
I think this issue is caused by isCollapsed function which is using range.isCollapsed from slate
isCollapsed(range: Range): boolean {
const { anchor, focus } = range
return Point.equals(anchor, focus)
},
the problem is arising because our anchor and focus are equal but we have different offsets which is making isCollapsed false
Yes, for the sake of reducing the complexity of the work, we haven't considered the expanded situation temporarily.
@felixfeng33 can i create a PR for this fix by adding below function
const isCollapsedInternalFunction = (range?: Range | null) => {
// Early return for null or undefined range
if (!range ||!range.anchor ||!range.focus) {
return false;
}
// Destructure the anchor and focus properties for easier access
const { anchor, focus } = range;
const { anchor, focus } = range;
// Check if both anchor and focus exist and have the same path coordinates
if (anchor && focus && anchor.path.length > 0 && focus.path.length > 0) {
return anchor.path[0] === focus.path[0] && anchor.path[1] === focus.path[1];
}
};
I think you can check the parent node props in the else statement.
In your solution could I selection cross block?
yes you can do cross selection in blocks as alignment is always block level
I have a question if a selection has first block center next block left what should be the overall alignment to be shown on top in mostly cases we show first block selection details can we do the same here
It's better the overall alignment is none.
I think we had better do some thing here since it's have more readability· if (isCollapsed(editor.selection)) { }else { do some check here }
We should check the value of all selected blocks using getNodeEntries
, and return true only if every
block has the same value. One different value makes it false (like marks).
Hey @zbeyens pls look into the PR that i opened regarding above bug