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

Alignment Issue : When whole text is selected it always shows left aligned #3171

Closed
kumarajay0412 opened this issue May 6, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@kumarajay0412
Copy link
Contributor

kumarajay0412 commented May 6, 2024

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

Screen.Recording.2024-05-06.at.12.17.37.PM.mov

Funding

  • You can sponsor this specific effort via a Polar.sh pledge below
  • We receive the pledge once the issue is completed & verified
Fund with Polar
@kumarajay0412 kumarajay0412 added the bug Something isn't working label May 6, 2024
@kumarajay0412
Copy link
Contributor Author

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

@felixfeng33
Copy link
Collaborator

Yes, for the sake of reducing the complexity of the work, we haven't considered the expanded situation temporarily.

@kumarajay0412
Copy link
Contributor Author

@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];
  }
};

@felixfeng33
Copy link
Collaborator

I think you can check the parent node props in the else statement.

@felixfeng33
Copy link
Collaborator

felixfeng33 commented May 6, 2024

In your solution could I selection cross block?
image

@kumarajay0412
Copy link
Contributor Author

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

@felixfeng33
Copy link
Collaborator

It's better the overall alignment is none.

@felixfeng33
Copy link
Collaborator

I think we had better do some thing here since it's have more readability·
if (isCollapsed(editor.selection)) {
}else {
do some check here
}

@zbeyens
Copy link
Member

zbeyens commented May 6, 2024

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).

@kumarajay0412
Copy link
Contributor Author

kumarajay0412 commented May 20, 2024

Hey @zbeyens pls look into the PR that i opened regarding above bug

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

3 participants