Skip to content

Commit

Permalink
fix get text selectRect error (#4263)
Browse files Browse the repository at this point in the history
Co-authored-by: Gerard Rovira <zurfyx@users.noreply.github.com>
  • Loading branch information
yjhtry and zurfyx committed Apr 4, 2023
1 parent 1859223 commit e27acc4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/lexical/src/LexicalSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3085,8 +3085,14 @@ export function updateDOMSelection(
? domSelection.getRangeAt(0)
: null;
if (selectionTarget !== null) {
// @ts-ignore Text nodes do have getBoundingClientRect
const selectionRect = selectionTarget.getBoundingClientRect();
let selectionRect: DOMRect;
if (selectionTarget instanceof Text) {
const range = document.createRange();
range.selectNode(selectionTarget);
selectionRect = range.getBoundingClientRect();
} else {
selectionRect = selectionTarget.getBoundingClientRect();
}
scrollIntoViewIfNeeded(editor, selectionRect, rootElement);
}
}
Expand Down

2 comments on commit e27acc4

@vercel
Copy link

@vercel vercel bot commented on e27acc4 Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical – ./packages/lexical-website

lexical.dev
lexicaljs.com
www.lexical.dev
lexical-fbopensource.vercel.app
lexical-git-main-fbopensource.vercel.app
lexicaljs.org

@vercel
Copy link

@vercel vercel bot commented on e27acc4 Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical-playground – ./packages/lexical-playground

lexical-playground-fbopensource.vercel.app
lexical-playground-git-main-fbopensource.vercel.app
playground.lexical.dev
lexical-playground.vercel.app

Please sign in to comment.