Go to next search result on enter
This commit is contained in:
parent
d2e1bed9d6
commit
bef37648b7
|
@ -328,7 +328,6 @@ export default class TreeMode extends Component {
|
||||||
|
|
||||||
/** @private */
|
/** @private */
|
||||||
handleNext = () => {
|
handleNext = () => {
|
||||||
// TODO: implement select next search result
|
|
||||||
const searchResults = search(this.state.data, this.state.search.text)
|
const searchResults = search(this.state.data, this.state.search.text)
|
||||||
if (searchResults) {
|
if (searchResults) {
|
||||||
const next = nextSearchResult(searchResults, this.state.search.active)
|
const next = nextSearchResult(searchResults, this.state.search.active)
|
||||||
|
@ -341,9 +340,6 @@ export default class TreeMode extends Component {
|
||||||
|
|
||||||
/** @private */
|
/** @private */
|
||||||
handlePrevious = () => {
|
handlePrevious = () => {
|
||||||
// TODO: implement select previous search result
|
|
||||||
console.log('previous search result...')
|
|
||||||
|
|
||||||
const searchResults = search(this.state.data, this.state.search.text)
|
const searchResults = search(this.state.data, this.state.search.text)
|
||||||
if (searchResults) {
|
if (searchResults) {
|
||||||
const previous = previousSearchResult(searchResults, this.state.search.active)
|
const previous = previousSearchResult(searchResults, this.state.search.active)
|
||||||
|
|
|
@ -23,7 +23,11 @@ export default class Search extends Component {
|
||||||
|
|
||||||
return h('div', {className: 'jsoneditor-search'}, [
|
return h('div', {className: 'jsoneditor-search'}, [
|
||||||
this.renderResultsCount(this.props.resultsCount),
|
this.renderResultsCount(this.props.resultsCount),
|
||||||
h('div', {key: 'box', className: 'jsoneditor-search-box'}, [
|
h('form', {
|
||||||
|
key: 'box',
|
||||||
|
className: 'jsoneditor-search-box',
|
||||||
|
onSubmit: this.handleSubmit
|
||||||
|
}, [
|
||||||
h('input', {
|
h('input', {
|
||||||
key: 'input',
|
key: 'input',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
|
@ -74,17 +78,33 @@ export default class Search extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleSubmit = (event) => {
|
||||||
|
event.stopPropagation()
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
|
if (this.timeout != null) {
|
||||||
|
// there is a pending change
|
||||||
|
this.debouncedOnChange()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// no pending change, go to next result
|
||||||
|
this.props.onNext()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleChange = (event) => {
|
handleChange = (event) => {
|
||||||
const text = event.target.value
|
const text = event.target.value
|
||||||
|
|
||||||
this.setState ({ text })
|
this.setState ({ text })
|
||||||
|
|
||||||
const delay = this.props.delay || 0
|
const delay = this.props.delay || 0
|
||||||
clearTimeout(this.timeout)
|
this.timeout = setTimeout(this.debouncedOnChange, delay)
|
||||||
this.timeout = setTimeout(this.callbackOnChange, delay)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callbackOnChange = () => {
|
debouncedOnChange = () => {
|
||||||
|
clearTimeout(this.timeout)
|
||||||
|
this.timeout = null
|
||||||
|
|
||||||
this.props.onChange(this.state.text)
|
this.props.onChange(this.state.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ div.jsoneditor-search {
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.jsoneditor-search-box {
|
form.jsoneditor-search-box {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue