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

Caret at the beginning of a line with rich text treated incorrectly #224

Closed
BartoszGrajdek opened this issue Mar 12, 2024 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@BartoszGrajdek
Copy link
Collaborator

BartoszGrajdek commented Mar 12, 2024

Description

Once cursor is placed at the beginning of a line with nested block right after the cursor browser starts providing incorrect rects. We had an investigation and it seems like it thinks that the caret is placed in a line above.

Possible solutions

  1. Wrap all text-leafs with span/p just like lexical does
  2. Try switching from using \n

Source

#220

Video

Video.mov
Useful snippet
function displaySpan() {
  const selection = window.getSelection();
  const caretRect = selection.getRangeAt(0).getClientRects()[0];
  const {height, top, left} = caretRect;
  const span = document.createElement('span');
  const body = document.querySelector('#root');
  span.classList.add('test');
  span.style.width = '1px';
  span.style.position = 'fixed';
  span.style.backgroundColor = 'orangered';
  span.style.height = `${height}px`;
  span.style.top = `${top}px`;
  span.style.left = `${left}px`;
  body.appendChild(span);
}

function hideSpan() {
  const span = document.querySelector('.test');
  span?.remove();
}
@BartoszGrajdek
Copy link
Collaborator Author

Note

It's now working much better, but there's still some refinement we could do

@BartoszGrajdek BartoszGrajdek self-assigned this Mar 28, 2024
@tomekzaw
Copy link
Collaborator

@BartoszGrajdek Is this bug still current?

@BartoszGrajdek
Copy link
Collaborator Author

It's fixed now 👍🏻

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

2 participants