@@ -45,8 +45,8 @@ function getTextUpToAnchor(selection: RangeSelection): string | null {
45
45
return anchorNode . getTextContent ( ) . slice ( 0 , anchorOffset ) ;
46
46
}
47
47
48
- function tryToPositionRange ( leadOffset : number , range : Range ) : boolean {
49
- const domSelection = window . getSelection ( ) ;
48
+ function tryToPositionRange ( leadOffset : number , range : Range , editorWindow : Window ) : boolean {
49
+ const domSelection = editorWindow . getSelection ( ) ;
50
50
if ( domSelection === null || ! domSelection . isCollapsed ) {
51
51
return false ;
52
52
}
@@ -236,7 +236,8 @@ export function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>({
236
236
useEffect ( ( ) => {
237
237
const updateListener = ( ) => {
238
238
editor . getEditorState ( ) . read ( ( ) => {
239
- const range = document . createRange ( ) ;
239
+ const editorWindow = editor . _window ?? window ;
240
+ const range = editorWindow . document . createRange ( ) ;
240
241
const selection = $getSelection ( ) ;
241
242
const text = getQueryTextForSearch ( editor ) ;
242
243
@@ -257,7 +258,7 @@ export function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>({
257
258
match !== null &&
258
259
! isSelectionOnEntityBoundary ( editor , match . leadOffset )
259
260
) {
260
- const isRangePositioned = tryToPositionRange ( match . leadOffset , range ) ;
261
+ const isRangePositioned = tryToPositionRange ( match . leadOffset , range , editorWindow ) ;
261
262
if ( isRangePositioned !== null ) {
262
263
startTransition ( ( ) =>
263
264
openTypeahead ( {
0 commit comments