-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Bug: Lexical editors in multiple windows #5050
Description
Steps To Reproduce
I'm not sure how to make an easy reproduction, but I noticed this in our app which pops out a DOM-only Electron window. It opens a new window via window.open() and renders to it from the parent window. As a result, there are multiple window objects that can host Lexical editors and one JS environment.
The current behavior
Lexical tracks lastTextEntryTimeStamp in a way that does not account for multiple windows over the lifetime of the application. It adds an event listener to the first window and not subsequent ones.
let lastTextEntryTimeStamp = 0;
function updateTimeStamp(event) {
lastTextEntryTimeStamp = event.timeStamp;
}
function initTextEntryListener(editor) {
if (lastTextEntryTimeStamp === 0) {
getWindow(editor).addEventListener("textInput", updateTimeStamp, true);
}
}
There were a number of buggy behaviors which resulted from this, due to applying input mutations during beforeinput. The most obvious bug was the MarkdownShortcutPlugin would duplicate the closing tag.
The expected behavior
Lexical should support editors in multiple windows.