From d216e02cb3e08e5bf89e3e9e51f62eb00d555b14 Mon Sep 17 00:00:00 2001 From: Ross Hadden Date: Wed, 3 Apr 2019 23:07:13 -0400 Subject: [PATCH] Collapse from anywhere (#102) * Collapse from anywhere within child, instead of just when highlighting the expanded node itself. Signed-off-by: Ross Hadden * Moved cursor to parent. Signed-off-by: Ross Hadden * Properly handled collapsing arrays. Signed-off-by: Ross Hadden --- fx.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fx.js b/fx.js index ed49f29..db19dd4 100644 --- a/fx.js +++ b/fx.js @@ -348,11 +348,17 @@ module.exports = function start(filename, source) { const [n, line] = getLine(program.y) program.showCursor() program.cursorPos(program.y, line.search(/\S/)) - const path = index.get(n) - if (expanded.has(path)) { - expanded.delete(path) - render() + let path = index.get(n) + if (typeof path === 'string' && !expanded.has(path)) { + path = path.replace(/(\.[^\[\].]+|\[\d+\])$/, '') + for (let y = program.y; y >= 0; --y) { + const [n, line] = getLine(y) + program.cursorPos(y, line.search(/\S/)) + if (index.get(n) === path) break + } } + expanded.delete(path) + render() }) box.on('click', function (mouse) {