@@ -941,6 +941,25 @@ export class AutocompleteEventHandler {
941941 constructor ( ) {
942942 this . autocompleteUI = new AutocompleteUI ( ) ;
943943 this . keyDownWithModifier = new Map ( ) ; // Keep track of keydown events with modifiers
944+ this . _debounceTimer = null ; // Timer ID for debounced search
945+ }
946+
947+ /**
948+ * Calls autocompleteUI.updateDisplay() with debounce for sequential search, or immediately for fast search.
949+ * @param {HTMLTextAreaElement } target
950+ */
951+ _triggerUpdateDisplay ( target ) {
952+ if ( settingValues . useFastSearch || settingValues . searchDebounceTime <= 0 ) {
953+ // FastSearch or debounce disabled: immediate update
954+ this . autocompleteUI . updateDisplay ( target ) ;
955+ } else {
956+ // Sequential search: debounced update
957+ clearTimeout ( this . _debounceTimer ) ;
958+ this . _debounceTimer = setTimeout ( ( ) => {
959+ this . autocompleteUI . updateDisplay ( target ) ;
960+ this . _debounceTimer = null ;
961+ } , settingValues . searchDebounceTime ) ;
962+ }
944963 }
945964
946965 /**
@@ -954,6 +973,7 @@ export class AutocompleteEventHandler {
954973
955974 const partialTag = getCurrentPartialTag ( event . target ) ;
956975 if ( partialTag . length <= 0 ) {
976+ clearTimeout ( this . _debounceTimer ) ; // Cancel pending debounced search
957977 this . autocompleteUI . hide ( ) ;
958978 }
959979 }
@@ -1064,7 +1084,7 @@ export class AutocompleteEventHandler {
10641084 // and default action is not prevented, update the display.
10651085 // This will typically be for character inputs, Delete, Backspace or IME composition.
10661086 if ( ! event . defaultPrevented ) {
1067- this . autocompleteUI . updateDisplay ( event . target ) ;
1087+ this . _triggerUpdateDisplay ( event . target ) ;
10681088 }
10691089 }
10701090
0 commit comments