1
0
Fork 0
mirror of synced 2024-07-04 22:11:23 +12:00

Use blur for change event RichTextField (#12649)

* Use blur for change event RichTextField

* Refactor
This commit is contained in:
melohagan 2024-01-03 09:26:52 +00:00 committed by GitHub
parent a4194e4d00
commit 0b21c36526
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,7 +19,7 @@
// Ensure the value is updated if the value prop changes outside the editor's
// control
$: checkValue(value)
$: mde?.codemirror.on("change", debouncedUpdate)
$: mde?.codemirror.on("blur", update)
$: if (readonly || disabled) {
mde?.togglePreview()
}
@ -30,21 +30,10 @@
}
}
const debounce = (fn, interval) => {
let timeout
return () => {
clearTimeout(timeout)
timeout = setTimeout(fn, interval)
}
}
const update = () => {
latestValue = mde.value()
dispatch("change", latestValue)
}
// Debounce the update function to avoid spamming it constantly
const debouncedUpdate = debounce(update, 250)
</script>
{#key height}