refactor: use const for planASucceeded, clarify LinkedIn comment
This commit is contained in:
@@ -123,12 +123,10 @@ export async function inputTextElement(element: HTMLElement, text: string) {
|
|||||||
// to Plan B (execCommand) if the text wasn't actually inserted.
|
// to Plan B (execCommand) if the text wasn't actually inserted.
|
||||||
//
|
//
|
||||||
// Plan A: Dispatch synthetic events
|
// Plan A: Dispatch synthetic events
|
||||||
// Works: React contenteditable, Quill, some LinkedIn versions.
|
// Works: React contenteditable, Quill, LinkedIn.
|
||||||
// Fails: Slate.js, some contenteditable editors that ignore synthetic events.
|
// Fails: Slate.js, some contenteditable editors that ignore synthetic events.
|
||||||
// Sequence: beforeinput -> mutation -> input -> change -> blur
|
// Sequence: beforeinput -> mutation -> input -> change -> blur
|
||||||
|
|
||||||
let planASucceeded = false
|
|
||||||
|
|
||||||
// Dispatch beforeinput + mutation + input for clearing
|
// Dispatch beforeinput + mutation + input for clearing
|
||||||
if (
|
if (
|
||||||
element.dispatchEvent(
|
element.dispatchEvent(
|
||||||
@@ -170,8 +168,7 @@ export async function inputTextElement(element: HTMLElement, text: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify Plan A worked by checking if the text was actually inserted
|
// Verify Plan A worked by checking if the text was actually inserted
|
||||||
const currentText = element.innerText.trim()
|
const planASucceeded = element.innerText.trim() === text.trim()
|
||||||
planASucceeded = currentText === text.trim()
|
|
||||||
|
|
||||||
if (!planASucceeded) {
|
if (!planASucceeded) {
|
||||||
// Plan B: execCommand fallback (deprecated but widely supported)
|
// Plan B: execCommand fallback (deprecated but widely supported)
|
||||||
|
|||||||
Reference in New Issue
Block a user