-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EditContext: Would it be useful to have an activeEditContext property on document? #97
Comments
We have been trying out different scenarios to test if the script re-entrancy would cause any side effects in EditContext or not. There is one test case where we had issues in how the EditContext was created inside an event handler which was created in a different realm than where the event got fired. Ex: const child = document.createElement("iframe");
document.body.appendChild(child);
const childDocument = child.contentDocument;
const textarea = childDocument.createElement('textarea');
childDocument.body.appendChild(textarea);
textarea.addEventListener("focusin", e => {
childDocument.childEditContext = new EditContext()
childDocument.childEditContext.focus();
childDocument.childEditContext.addEventListener("textupdate", e => {
console.log("iframe textupdate event fired");
child.remove();
});
childDocument.childEditContext.addEventListener("textformatupdate", e => {
console.log("iframe textformatupdate event fired");
});
});
textarea.focus(); In this scenario, the EditContext is being created on focusin event. This focusin event handler is defined in the context of the parent document so when this event is fired, the EditContext gets initialized and stored in the parent document instead of the contentDocument where it is supposed to be initialized. This leads EditContext to not fire any textupdate/textformatupdate events in the iframe when the user starts a composition inside the iframe. It does fire those events when the user starts the composition outside the iframe.
|
Could you add examples for proposal 1 and 2? |
For#1 We could have a property in the document like document.activeEditContext which is set to the focused EditContext. document.activeEditContext = new EditContext() or have multiple EditContexts and set this property to point to the active one const editContext = new EditContext(); document.activeEditContext = editContext; For#2 const editContext = new EditContext(document); When editContext.focus() is called, the document in the editContext will be used to set the active EditContext if the document is the active document and fire events to this EditContext later when there is a composition event. |
I like the idea of proceeding with your 2nd option. @snianu want to take a stab at an update for this? |
@alexkeng FYI. |
This issue was transferred to the Edit-context repo: w3c/edit-context#4 |
This question was raised in this thread and we want to see what others think about this scenario.
The text was updated successfully, but these errors were encountered: