Fix expanding nested search results

This commit is contained in:
Jos de Jong 2020-07-26 10:56:04 +02:00
parent ad4572d21e
commit 23067b4638
6 changed files with 16 additions and 15 deletions

View File

@ -253,6 +253,7 @@
function changeSearchText (text) {
searchText = text
searchResult = search(doc, searchText, searchResult)
focusActiveSearchResult(searchResult && searchResult.activeItem)
}
function nextSearchResult () {
@ -331,7 +332,7 @@
return stateUtils(getIn(doc, path), childState, [], () => expanded, true)
})
} else {
state = setIn(state, path.concat(STATE_EXPANDED), expanded)
state = setIn(state, path.concat(STATE_EXPANDED), expanded, true)
}
}
@ -341,7 +342,7 @@
* @param {boolean} limit
*/
function handleLimit (path, limit) {
state = setIn(state, path.concat(STATE_LIMIT), limit)
state = setIn(state, path.concat(STATE_LIMIT), limit, true)
}
/**

View File

@ -442,7 +442,7 @@
{:else}
<span class="delimiter"> &#123;</span>
<button class="tag" on:click={handleExpand}>{Object.keys(value).length} props</button>
<span class="delimiter">}</span>
<span class="delimiter">&rbrace;</span>
{/if}
</div>
{#if expanded}
@ -472,7 +472,7 @@
</div>
</div>
<div class="footer" style={indentationStyle}>
<span class="delimiter">}</span>
<span class="delimiter">&rbrace;</span>
</div>
{/if}
{:else}

View File

@ -1,4 +1,4 @@
import { first, initial, isEmpty, isEqual, last } from 'lodash-es'
import { isEqual } from 'lodash-es'
import { STATE_PROPS } from './constants.js'
import { getIn } from './utils/immutabilityHelpers.js'
import { compileJSONPointer, parseJSONPointer } from './utils/jsonPointer.js'

View File

@ -41,7 +41,7 @@ export function search (doc, searchText, previousResult) {
const activeIndex = flatItems.findIndex(item => isEqual(item, activeItem))
const itemsWithActive = (items && activeItem)
? setIn(items, activeItem.path.concat(activeItem.what), 'search active')
? setIn(items, activeItem.path.concat(activeItem.what), 'search active', true)
: items
return {
@ -66,7 +66,7 @@ export function searchNext (searchResult) {
const nextActiveItem = searchResult.flatItems[nextActiveIndex]
const itemsWithActive = nextActiveItem
? setIn(searchResult.items, nextActiveItem.path.concat(nextActiveItem.what), 'search active')
? setIn(searchResult.items, nextActiveItem.path.concat(nextActiveItem.what), 'search active', true)
: searchResult.items
return {
@ -89,7 +89,7 @@ export function searchPrevious (searchResult) {
const previousActiveItem = searchResult.flatItems[previousActiveIndex]
const itemsWithActive = previousActiveItem
? setIn(searchResult.items, previousActiveItem.path.concat(previousActiveItem.what), 'search active')
? setIn(searchResult.items, previousActiveItem.path.concat(previousActiveItem.what), 'search active', true)
: searchResult.items
return {

View File

@ -5,7 +5,7 @@ import {
STATE_LIMIT,
STATE_PROPS
} from '../constants.js'
import { setIn } from './immutabilityHelpers.js'
import { getIn, setIn } from './immutabilityHelpers.js'
import { isObject, isObjectOrArray } from './typeUtils.js'
import { updateProps } from './updateProps.js'
@ -87,7 +87,7 @@ export function expandPath (state, path) {
for (let i = 1; i < path.length; i++) {
const partialPath = path.slice(0, i)
// FIXME: setIn has to create object first
updatedState = setIn(updatedState, partialPath.concat(STATE_EXPANDED), true)
updatedState = setIn(updatedState, partialPath.concat(STATE_EXPANDED), true, true)
// if needed, enlarge the limit such that the search result becomes visible
const key = path[i]
@ -95,7 +95,7 @@ export function expandPath (state, path) {
const limit = getIn(updatedState, partialPath.concat(STATE_LIMIT)) || DEFAULT_LIMIT
if (key > limit) {
const newLimit = Math.ceil(key / DEFAULT_LIMIT) * DEFAULT_LIMIT
updatedState = setIn(updatedState, partialPath.concat(STATE_LIMIT), newLimit)
updatedState = setIn(updatedState, partialPath.concat(STATE_LIMIT), newLimit, true)
}
}
}

View File

@ -58,18 +58,18 @@ export function patchProps (state, operations) {
const newIndex = props.findIndex(item => item.key === newKey)
if (newIndex !== -1) {
const updatedProps = deleteIn(props, [newIndex])
updatedState = setIn(updatedState, parentPath.concat([STATE_PROPS]), updatedProps)
updatedState = setIn(updatedState, parentPath.concat([STATE_PROPS]), updatedProps, true)
}
// Rename the key in the object's props so it maintains its identity and hence its index
updatedState = setIn(updatedState, parentPath.concat([STATE_PROPS, oldIndex, 'key']), newKey)
updatedState = setIn(updatedState, parentPath.concat([STATE_PROPS, oldIndex, 'key']), newKey, true)
} else {
// operation.from and operation.path are the same:
// property is moved but stays the same -> move it to the end of the props
const oldProp = props[oldIndex]
const updatedProps = insertAt(deleteIn(props, [oldIndex]), [props.length - 1], oldProp)
updatedState = setIn(updatedState, parentPath.concat([STATE_PROPS]), updatedProps)
updatedState = setIn(updatedState, parentPath.concat([STATE_PROPS]), updatedProps, true)
}
}
}
@ -90,7 +90,7 @@ export function patchProps (state, operations) {
}
const updatedProps = insertAt(props, [props.length], newProp)
updatedState = setIn(updatedState, parentPath.concat([STATE_PROPS]), updatedProps)
updatedState = setIn(updatedState, parentPath.concat([STATE_PROPS]), updatedProps, true)
}
}
}