Skip to content

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

Description

@BartoszGrajdek

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();
}

Activity

  1. BartoszGrajdek commented on Mar 28, 2024

    @BartoszGrajdek
    ContributorAuthor

    Note

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

  2. tomekzaw commented on Sep 19, 2024

    @tomekzaw
    Contributor

    @BartoszGrajdek Is this bug still current?

  3. BartoszGrajdek commented on Sep 19, 2024

    @BartoszGrajdek
    ContributorAuthor

    It's fixed now 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions