Skip to content

Commit

Permalink
Fix expand all under cursor and add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Nov 6, 2019
1 parent 027b1a8 commit 33ea17b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
15 changes: 10 additions & 5 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,18 @@ Next commands available in interactive mode:
| Key | Command |
|-------------------------------|-------------------------|
| `q` or `Esc` or `Ctrl`+`c` | Exit |
| `e`/`E` | Expand/Collapse all |
| `g`/`G` | Goto top/bottom |
| `up`/`down` or `k/j` | Move cursor up/down |
| `left`/`right` or `h/l` | Expand/Collapse |
| `up` or `k` | Move cursor up |
| `down` or `j` | Move cursor down |
| `left` or `h` | Collapse |
| `right` or `l` | Expand |
| `Shift`+`right` or `L` | Expand all under cursor |
| `e` | Expand all |
| `E` | Collapse all |
| `g` | Scroll to top |
| `G` | Scroll to bottom |
| `.` | Edit filter |
| `/` | Search |
| `n` | Goto next found pattern |
| `n` | Find next |

These commands are available when editing the filter:

Expand Down
18 changes: 1 addition & 17 deletions fx.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ module.exports = function start(filename, source) {
program.showCursor()
program.cursorPos(program.y, line.search(/\S/))
const path = index.get(n)
const subJson = reduce(json, path)
const subJson = reduce(json, 'this' + path)
for (let p of dfs(subJson, path)) {
if (expanded.size < 1000) {
expanded.add(p)
Expand Down Expand Up @@ -398,22 +398,6 @@ 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)
Expand Down
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ const usage = `
Usage
$ fx [code ...]
Shortcuts
q or Esc or Ctrl+c Exit
up or k Move cursor up
down or j Move cursor down
left or h Collapse
right or l Expand
Shift+right or L Expand all under cursor
e Expand all
E Collapse all
g Scroll to top
G Scroll to bottom
. Edit filter
/ Search
n Find next
Examples
$ echo '{"key": "value"}' | fx 'x => x.key'
value
Expand Down

0 comments on commit 33ea17b

Please sign in to comment.