Skip to content

Conversation

@R0lin
Copy link

@R0lin R0lin commented Aug 7, 2025

When selecting an autocomplete suggestion (e.g., after typing #), the Textcomplete plugin triggers the context() and search() functions twice instead of once. This results in unexpected double workflow cycles.

Root Cause

In @textcomplete/textarea, the applySearchResult function internally uses the update package to update the text content. The update function already dispatches a native input event after applying the change.

 if (!document.execCommand("insertText", false, strB2)) {
    // Document.execCommand returns false if the command is not supported.
    // Firefox and IE returns false in this case.
    el.value = next

    // Dispatch input event. Note that `new Event("input")` throws an error on IE11
    const event = document.createEvent("Event")
    event.initEvent("input", true, true)
    el.dispatchEvent(event)
 }

However, immediately after that, applySearchResult dispatches another input event manually:

 if (Array.isArray(replace)) {
    update(this.el, replace[0], replace[1])
    if (this.el) {
      this.el.dispatchEvent(createCustomEvent("input"))
    }
 }

This results in two input events for a single action — triggering duplicate plugin workflows.

Fix

Commented out the redundant input event dispatch in applySearchResult. This avoids firing duplicate input events and ensures only one workflow/search cycle is triggered after selecting a suggestion.

Verified

  • Confirmed with logging: now only a single workflow is started after selecting an autocomplete item.
  • Behavior matches expectation — no adverse side effects observed.

Related

Fixes behavior demonstrated in this bug report:
Double workflow/search triggered after selection in strategy matching (version 0.1.13)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant