diff --git a/DOCS.md b/DOCS.md index 5444d39..c0e709a 100644 --- a/DOCS.md +++ b/DOCS.md @@ -271,6 +271,7 @@ Next commands available in interactive mode: | `left` or `h` | Collapse | | `right` or `l` | Expand | | `Shift`+`right` or `L` | Expand all under cursor | +| `Shift`+`left` or `K` | Collapse all under cursor | | `e` | Expand all | | `E` | Collapse all | | `g` | Scroll to top | diff --git a/fx.js b/fx.js index 748c9ae..751c10b 100644 --- a/fx.js +++ b/fx.js @@ -363,6 +363,29 @@ module.exports = function start(filename, source, prev = {}) { render() }) + box.key(['S-left', 'S-k'], function () { + hideStatusBar() + const [n, line] = getLine(program.y) + program.showCursor() + program.cursorPos(program.y, line.search(/\S/)) + const path = index.get(n) + if (!path) { + // collapse on top level (should render like after run) + expanded.clear() + expanded.add('') + } else { + const subJson = reduce(json, 'this' + path) + for (let p of dfs(subJson, path)) { + if (expanded.size < 1000) { + expanded.delete(p) + } else { + break + } + } + } + render() + }) + box.key(['left', 'h'], function () { hideStatusBar() const [n, line] = getLine(program.y)