refactor: use const for planASucceeded, clarify LinkedIn comment

This commit is contained in:
voidborne-d
2026-03-20 07:08:45 +00:00
parent 2f92a9cb32
commit 2e18bd862d

View File

@@ -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)