Fix clearing search result
This commit is contained in:
parent
5fb69ffcc5
commit
040fe12d75
|
@ -198,23 +198,12 @@ export default class TreeMode extends Component {
|
|||
// data = addErrors(data, this.getErrors())
|
||||
// }
|
||||
|
||||
// enrich the data with search results
|
||||
// TODO: reimplement search and selection
|
||||
const searchResults = []
|
||||
// const searchResults = this.state.search.text ? search(data, this.state.search.text) : null
|
||||
// if (searchResults) {
|
||||
// data = applySearchResults(data, searchResults, this.state.search.active)
|
||||
// }
|
||||
// if (this.state.selection) {
|
||||
// data = applySelection(data, this.state.selection)
|
||||
// }
|
||||
|
||||
return h('div', {
|
||||
className: `jsoneditor jsoneditor-mode-${props.mode}`,
|
||||
onKeyDown: this.handleKeyDown,
|
||||
'data-jsoneditor': 'true'
|
||||
}, [
|
||||
this.renderMenu(searchResults),
|
||||
this.renderMenu(),
|
||||
|
||||
h('div', {
|
||||
key: 'contents',
|
||||
|
@ -244,7 +233,7 @@ export default class TreeMode extends Component {
|
|||
])
|
||||
}
|
||||
|
||||
renderMenu (searchResults: [] | null) {
|
||||
renderMenu () {
|
||||
let items = [
|
||||
h('button', {
|
||||
key: 'expand-all',
|
||||
|
@ -301,7 +290,7 @@ export default class TreeMode extends Component {
|
|||
h('div', {key: 'search', className: 'jsoneditor-menu-panel-right'},
|
||||
h(Search, {
|
||||
text: this.state.search.text,
|
||||
searchResults,
|
||||
resultCount: this.state.search.matches ? this.state.search.matches.length : 0,
|
||||
onChange: this.handleSearch,
|
||||
onNext: this.handleNext,
|
||||
onPrevious: this.handlePrevious,
|
||||
|
@ -592,7 +581,6 @@ export default class TreeMode extends Component {
|
|||
|
||||
handleSearch = (text) => {
|
||||
const { eson, matches, active } = search(this.state.eson, text)
|
||||
|
||||
if (matches.length > 0) {
|
||||
this.setState({
|
||||
search: { text, active, matches },
|
||||
|
@ -604,7 +592,8 @@ export default class TreeMode extends Component {
|
|||
}
|
||||
else {
|
||||
this.setState({
|
||||
search: { text, active, matches }
|
||||
search: { text, active, matches },
|
||||
eson
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ export default class Search extends Component {
|
|||
|
||||
render () {
|
||||
return h('div', {className: 'jsoneditor-search'}, [
|
||||
this.renderResultsCount(this.props.searchResults),
|
||||
this.renderResultsCount(this.props.resultCount),
|
||||
h('form', {
|
||||
key: 'box',
|
||||
className: 'jsoneditor-search-box',
|
||||
|
@ -54,21 +54,19 @@ export default class Search extends Component {
|
|||
])
|
||||
}
|
||||
|
||||
renderResultsCount (searchResults : []) {
|
||||
if (!searchResults) {
|
||||
renderResultsCount (resultCount) {
|
||||
if (resultCount === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
const count = searchResults.length
|
||||
|
||||
if (count === 0) {
|
||||
if (resultCount === 0) {
|
||||
return h('div', {key: 'count', className: 'jsoneditor-results'}, '(no results)')
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
const suffix = count === 1 ? ' result' : ' results'
|
||||
if (resultCount > 0) {
|
||||
const suffix = resultCount === 1 ? ' result' : ' results'
|
||||
|
||||
return h('div', {key: 'count', className: 'jsoneditor-results'}, count + suffix)
|
||||
return h('div', {key: 'count', className: 'jsoneditor-results'}, resultCount + suffix)
|
||||
}
|
||||
|
||||
return null
|
||||
|
|
|
@ -352,7 +352,7 @@ export function addErrors (eson: ESON, errors) {
|
|||
/**
|
||||
* Search some text in all properties and values
|
||||
* @param {ESON} eson
|
||||
* @param {String} text
|
||||
* @param {String} text Search text
|
||||
* @return {{eson: ESON, matches: ESONPointer[], active: ESONPointer}} Returns search result:
|
||||
* An updated eson object containing the search results,
|
||||
* and an array with the paths of all matches
|
||||
|
@ -367,7 +367,7 @@ export function search (eson, text) {
|
|||
|
||||
// check property name
|
||||
const prop = last(path)
|
||||
if (typeof prop === 'string' && containsCaseInsensitive(prop, text)) {
|
||||
if (typeof prop === 'string' && text !== '' && containsCaseInsensitive(prop, text)) {
|
||||
const searchState = isEmpty(matches) ? 'active' : 'normal'
|
||||
matches.push({path, area: 'property'})
|
||||
updatedValue = setIn(updatedValue, ['_meta', 'searchProperty'], searchState)
|
||||
|
@ -377,7 +377,7 @@ export function search (eson, text) {
|
|||
}
|
||||
|
||||
// check value
|
||||
if (value._meta.type === 'value' && containsCaseInsensitive(value._meta.value, text)) {
|
||||
if (value._meta.type === 'value' && text !== '' && containsCaseInsensitive(value._meta.value, text)) {
|
||||
const searchState = isEmpty(matches) ? 'active' : 'normal'
|
||||
matches.push({path, area: 'value'})
|
||||
updatedValue = setIn(updatedValue, ['_meta', 'searchValue'], searchState)
|
||||
|
|
Loading…
Reference in New Issue