From a9a453f51f54c6dad79724c783717327d1a56ece Mon Sep 17 00:00:00 2001 From: jos Date: Thu, 5 Jan 2017 15:00:05 +0100 Subject: [PATCH] Fixed expanding root node too when expanding path --- src/components/TreeMode.js | 15 ++++++--------- src/jsonData.js | 3 ++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/components/TreeMode.js b/src/components/TreeMode.js index 18fab0d..60e2892 100644 --- a/src/components/TreeMode.js +++ b/src/components/TreeMode.js @@ -334,8 +334,8 @@ export default class TreeMode extends Component { data: expandPath(this.state.data, active.path) }) - // scroll to active search result - this.scrollTo(active.path) + // scroll to active search result (on next tick, after this path has been expanded) + setTimeout(() => this.scrollTo(active.path)) } else { this.setState({ @@ -355,11 +355,8 @@ export default class TreeMode extends Component { data: expandPath(this.state.data, next && next.path) }) - // scroll to the active result - const name = compileJSONPointer(next.path) - - // scroll to the active result - this.scrollTo(next.path) + // scroll to the active result (on next tick, after this path has been expanded) + setTimeout(() => this.scrollTo(next.path)) } } @@ -374,8 +371,8 @@ export default class TreeMode extends Component { data: expandPath(this.state.data, previous && previous.path) }) - // scroll to the active result - this.scrollTo(previous.path) + // scroll to the active result (on next tick, after this path has been expanded) + setTimeout(() => this.scrollTo(previous.path)) } } diff --git a/src/jsonData.js b/src/jsonData.js index d75cbdf..a300cd6 100644 --- a/src/jsonData.js +++ b/src/jsonData.js @@ -503,9 +503,10 @@ export function expandPath (data: JSONData, path: Path) { let updatedData = data if (path) { + updatedData = expand(updatedData, [], true) // expand root + for (let i = 0; i < path.length; i++) { const pathPart = path.slice(0, i + 1) - // console.log('expandPath', path, i, pathPart) updatedData = expand(updatedData, pathPart, true) } }