1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-20 19:08:21 +00:00

change search Chinese (#5744)

This commit is contained in:
Michael An
2023-11-08 20:52:59 +08:00
committed by GitHub
parent d4ad64c395
commit c79d841a8f

View File

@@ -56,10 +56,13 @@ class Search extends Component {
this.searchResultListRef = React.createRef(); this.searchResultListRef = React.createRef();
this.timer = null; this.timer = null;
this.indexStateTimer = null; this.indexStateTimer = null;
this.isChineseInput = false;
} }
componentDidMount() { componentDidMount() {
document.addEventListener('keydown', this.onDocumentKeydown); document.addEventListener('keydown', this.onDocumentKeydown);
document.addEventListener('compositionstart', this.onCompositionStart);
document.addEventListener('compositionend', this.onCompositionEnd);
if (enableSeafileAI && this.props.isLibView) { if (enableSeafileAI && this.props.isLibView) {
this.queryLibraryIndexState(); this.queryLibraryIndexState();
} }
@@ -80,10 +83,27 @@ class Search extends Component {
componentWillUnmount() { componentWillUnmount() {
document.removeEventListener('keydown', this.onDocumentKeydown); document.removeEventListener('keydown', this.onDocumentKeydown);
document.removeEventListener('compositionstart', this.onCompositionStart);
document.removeEventListener('compositionend', this.onCompositionEnd);
this.indexStateTimer && clearInterval(this.indexStateTimer); this.indexStateTimer && clearInterval(this.indexStateTimer);
this.timer && clearTimeout(this.timer); this.timer && clearTimeout(this.timer);
this.isChineseInput = false;
} }
onCompositionStart = () => {
this.isChineseInput = true;
};
onCompositionEnd = () => {
this.isChineseInput = false;
// chromecompositionstart -> onChange -> compositionend
// not chromecompositionstart -> compositionend -> onChange
// The onChange event will setState and change input value, then setTimeout to initiate the search
setTimeout(() => {
this.onSearch(this.state.searchMode === SEARCH_MODE.NORMAL);
}, 1);
};
onDocumentKeydown = (e) => { onDocumentKeydown = (e) => {
if (isHotkey('mod+f')(e)) { if (isHotkey('mod+f')(e)) {
e.preventDefault(); e.preventDefault();
@@ -167,7 +187,9 @@ class Search extends Component {
this.setState({ value: newValue }, () => { this.setState({ value: newValue }, () => {
if (this.inputValue === newValue.trim()) return; if (this.inputValue === newValue.trim()) return;
this.inputValue = newValue.trim(); this.inputValue = newValue.trim();
this.onSearch(!this.props.isLibView || !enableSeafileAI); if (!this.isChineseInput) {
this.onSearch(!this.props.isLibView || !enableSeafileAI);
}
}); });
}; };