mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-11 03:41:12 +00:00
fix search global use keyboard (#6884)
This commit is contained in:
@@ -132,8 +132,9 @@ class Search extends Component {
|
|||||||
onUp = (e) => {
|
onUp = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const { highlightIndex, resultItems } = this.state;
|
const { highlightIndex, resultItems, isResultGetted } = this.state;
|
||||||
|
|
||||||
|
// 01 init search, display and highlight recent search results
|
||||||
if (this.state.showRecent) {
|
if (this.state.showRecent) {
|
||||||
if (highlightIndex > 0) {
|
if (highlightIndex > 0) {
|
||||||
this.setState({ highlightIndex: highlightIndex - 1 }, () => {
|
this.setState({ highlightIndex: highlightIndex - 1 }, () => {
|
||||||
@@ -148,8 +149,8 @@ class Search extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// global searching, searched repos needs to support up and down keys
|
// 02 global search, display and highlight searched repos
|
||||||
if (!this.props.repoID && resultItems.length > 0) {
|
if (!this.props.repoID && resultItems.length > 0 && !isResultGetted) {
|
||||||
let highlightSearchTypesIndex = this.state.highlightSearchTypesIndex - 1;
|
let highlightSearchTypesIndex = this.state.highlightSearchTypesIndex - 1;
|
||||||
if (highlightSearchTypesIndex < 0) {
|
if (highlightSearchTypesIndex < 0) {
|
||||||
highlightSearchTypesIndex = resultItems.length;
|
highlightSearchTypesIndex = resultItems.length;
|
||||||
@@ -165,7 +166,8 @@ class Search extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.state.isResultGetted) {
|
// 03 Internal repo search, highlight search types
|
||||||
|
if (!isResultGetted) {
|
||||||
let highlightSearchTypesIndex = this.state.highlightSearchTypesIndex - 1;
|
let highlightSearchTypesIndex = this.state.highlightSearchTypesIndex - 1;
|
||||||
if (highlightSearchTypesIndex < 0) {
|
if (highlightSearchTypesIndex < 0) {
|
||||||
highlightSearchTypesIndex = this.state.searchTypesMax;
|
highlightSearchTypesIndex = this.state.searchTypesMax;
|
||||||
@@ -174,6 +176,7 @@ class Search extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 04 When there are search results, highlighte searched items
|
||||||
if (highlightIndex > 0) {
|
if (highlightIndex > 0) {
|
||||||
this.setState({ highlightIndex: highlightIndex - 1 }, () => {
|
this.setState({ highlightIndex: highlightIndex - 1 }, () => {
|
||||||
if (this.highlightRef) {
|
if (this.highlightRef) {
|
||||||
@@ -189,8 +192,9 @@ class Search extends Component {
|
|||||||
onDown = (e) => {
|
onDown = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const { highlightIndex, resultItems } = this.state;
|
const { highlightIndex, resultItems, isResultGetted } = this.state;
|
||||||
|
|
||||||
|
// 01 init search, display and highlight recent search results
|
||||||
if (this.state.showRecent) {
|
if (this.state.showRecent) {
|
||||||
const visitedItems = JSON.parse(localStorage.getItem(this.storeKey)) || [];
|
const visitedItems = JSON.parse(localStorage.getItem(this.storeKey)) || [];
|
||||||
if (highlightIndex < visitedItems.length - 1) {
|
if (highlightIndex < visitedItems.length - 1) {
|
||||||
@@ -208,8 +212,8 @@ class Search extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// global searching, searched repos needs to support up and down keys
|
// 02 global search, display and highlight searched repos
|
||||||
if (!this.props.repoID && resultItems.length > 0) {
|
if (!this.props.repoID && resultItems.length > 0 && !isResultGetted) {
|
||||||
let highlightSearchTypesIndex = this.state.highlightSearchTypesIndex + 1;
|
let highlightSearchTypesIndex = this.state.highlightSearchTypesIndex + 1;
|
||||||
if (highlightSearchTypesIndex > resultItems.length) {
|
if (highlightSearchTypesIndex > resultItems.length) {
|
||||||
highlightSearchTypesIndex = 0;
|
highlightSearchTypesIndex = 0;
|
||||||
@@ -227,6 +231,7 @@ class Search extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 03 Internal repo search, highlight search types
|
||||||
if (!this.state.isResultGetted) {
|
if (!this.state.isResultGetted) {
|
||||||
let highlightSearchTypesIndex = this.state.highlightSearchTypesIndex + 1;
|
let highlightSearchTypesIndex = this.state.highlightSearchTypesIndex + 1;
|
||||||
if (highlightSearchTypesIndex > this.state.searchTypesMax) {
|
if (highlightSearchTypesIndex > this.state.searchTypesMax) {
|
||||||
@@ -236,6 +241,7 @@ class Search extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 04 When there are search results, highlighte searched items
|
||||||
if (highlightIndex < resultItems.length - 1) {
|
if (highlightIndex < resultItems.length - 1) {
|
||||||
this.setState({ highlightIndex: highlightIndex + 1 }, () => {
|
this.setState({ highlightIndex: highlightIndex + 1 }, () => {
|
||||||
if (this.highlightRef) {
|
if (this.highlightRef) {
|
||||||
@@ -264,8 +270,8 @@ class Search extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// global searching, searched repos needs to support enter
|
// global searching, searched repos needs to support enter
|
||||||
const { highlightSearchTypesIndex, resultItems } = this.state;
|
const { highlightSearchTypesIndex, resultItems, isResultGetted } = this.state;
|
||||||
if (!this.props.repoID && resultItems.length > 0) {
|
if (!this.props.repoID && resultItems.length > 0 && !isResultGetted) {
|
||||||
if (highlightSearchTypesIndex === 0) {
|
if (highlightSearchTypesIndex === 0) {
|
||||||
this.searchAllRepos();
|
this.searchAllRepos();
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user