Skip to content

Commit

Permalink
refactor(NcRichContenteditable): cancel autoComplete on close
Browse files Browse the repository at this point in the history
- Correctly implement `debounced` method, so that debouncedFunction properties are available and each component instance has its own debounce
- Clear debounce on autoComplete close

Signed-off-by: Grigorii K. Shartsev <[email protected]>
  • Loading branch information
ShGKme committed Feb 5, 2024
1 parent 466d368 commit 81cc8e8
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/components/NcRichContenteditable/NcRichContenteditable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,15 @@ export default {
delete listeners.paste
return listeners
},
/**
* Compute debounce function for the autocomplete function
*/
debouncedAutoComplete() {
return debounce(async (search, callback) => {
this.autoComplete(search, callback)
}, 100)
},
},
watch: {
Expand Down Expand Up @@ -837,13 +846,6 @@ export default {
this.$emit('submit', event)
},
/**
* Debounce the autocomplete function
*/
debouncedAutoComplete: debounce(async function(search, callback) {
this.autoComplete(search, callback)
}, 100),
onKeyUp(event) {
// prevent tribute from opening on keyup
event.stopImmediatePropagation()
Expand All @@ -870,6 +872,10 @@ export default {
// So we have to manually update the class
// The default class is "tribute-container"
this.getTributeContainer().setAttribute('class', this.tribute.current.collection.containerClass || 'tribute-container')
} else {
// Cancel loading data for autocomplete
// Otherwise it could be received when another autocomplete is already opened
this.debouncedAutoComplete.clear()
}
},
},
Expand Down

0 comments on commit 81cc8e8

Please sign in to comment.