Debounce language detection

This commit is contained in:
Thomas Steiner 2025-07-11 08:37:44 +02:00
parent 0733590c3b
commit 3e1e6762aa

View File

@ -10,6 +10,8 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
import { length } from 'stringz'; import { length } from 'stringz';
import debounce from 'lodash.debounce';
import { missingAltTextModal } from 'mastodon/initial_state'; import { missingAltTextModal } from 'mastodon/initial_state';
import { changeComposeLanguage } from 'mastodon/actions/compose'; import { changeComposeLanguage } from 'mastodon/actions/compose';
@ -110,6 +112,7 @@ class ComposeForm extends ImmutablePureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
this.textareaRef = createRef(null); this.textareaRef = createRef(null);
this.debouncedHandleKeyUp = debounce(this._handleKeyUp.bind(this), 500);
} }
handleChange = (e) => { handleChange = (e) => {
@ -122,7 +125,11 @@ class ComposeForm extends ImmutablePureComponent {
} }
}; };
handleKeyUp = async (e) => { handleKeyUp = (e) => {
this.debouncedHandleKeyUp(e);
}
_handleKeyUp = async (e) => {
if (!supportsLanguageDetector) { if (!supportsLanguageDetector) {
return; return;
} }
@ -211,6 +218,7 @@ class ComposeForm extends ImmutablePureComponent {
componentWillUnmount () { componentWillUnmount () {
if (this.timeout) clearTimeout(this.timeout); if (this.timeout) clearTimeout(this.timeout);
this.debouncedHandleKeyUp.cancel();
} }
componentDidUpdate (prevProps) { componentDidUpdate (prevProps) {