From 83efa1d10953fd8e06e86435c3e455db4b4c912a Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Thu, 4 Apr 2019 10:46:17 +0700 Subject: [PATCH] Add collapse/expand all under cursor functionality --- fx.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/fx.js b/fx.js index 8b0ae8e..1923c8f 100644 --- a/fx.js +++ b/fx.js @@ -343,6 +343,24 @@ module.exports = function start(filename, source) { } }) + // Expand everything under cursor. + box.key(['S-right', 'S-l'], function () { + hideStatusBar() + const [n, line] = getLine(program.y) + program.showCursor() + program.cursorPos(program.y, line.search(/\S/)) + const path = index.get(n) + const subJson = reduce(json, path) + for (let p of dfs(subJson, path)) { + if (expanded.size < 1000) { + expanded.add(p) + } else { + break + } + } + render() + }) + box.key(['left', 'h'], function () { hideStatusBar() const [n, line] = getLine(program.y) @@ -380,6 +398,22 @@ module.exports = function start(filename, source) { } }) + // Collapse all under cursor. + box.key(['S-left', 'S-h'], function () { + hideStatusBar() + const [n, line] = getLine(program.y) + program.showCursor() + program.cursorPos(program.y, line.search(/\S/)) + const path = index.get(n) + const subJson = reduce(json, path) + for (let p of dfs(subJson, path)) { + if (expanded.has(p)) { + expanded.delete(p) + } + } + render() + }) + box.on('click', function (mouse) { hideStatusBar() const [n, line] = getLine(mouse.y)