Skip to content

Commit

Permalink
Allow LexicalTypeaheadMenuPlugin to work when inside an iframe (#5044)
Browse files Browse the repository at this point in the history
Co-authored-by: tahkiu <39982625+tahkiu@users.noreply.github.com>
Co-authored-by: Maksim Horbachevsky <fantactuka@gmail.com>
  • Loading branch information
3 people committed Sep 28, 2023
1 parent 3ef3cb7 commit f0933ba
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/lexical-react/src/LexicalTypeaheadMenuPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function getTextUpToAnchor(selection: RangeSelection): string | null {
return anchorNode.getTextContent().slice(0, anchorOffset);
}

function tryToPositionRange(leadOffset: number, range: Range): boolean {
const domSelection = window.getSelection();
function tryToPositionRange(leadOffset: number, range: Range, editorWindow: Window): boolean {
const domSelection = editorWindow.getSelection();
if (domSelection === null || !domSelection.isCollapsed) {
return false;
}
Expand Down Expand Up @@ -236,7 +236,8 @@ export function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>({
useEffect(() => {
const updateListener = () => {
editor.getEditorState().read(() => {
const range = document.createRange();
const editorWindow = editor._window ?? window;
const range = editorWindow.document.createRange();
const selection = $getSelection();
const text = getQueryTextForSearch(editor);

Expand All @@ -257,7 +258,7 @@ export function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>({
match !== null &&
!isSelectionOnEntityBoundary(editor, match.leadOffset)
) {
const isRangePositioned = tryToPositionRange(match.leadOffset, range);
const isRangePositioned = tryToPositionRange(match.leadOffset, range, editorWindow);
if (isRangePositioned !== null) {
startTransition(() =>
openTypeahead({
Expand Down

1 comment on commit f0933ba

@vercel
Copy link

@vercel vercel bot commented on f0933ba Sep 28, 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

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

Please sign in to comment.