jless icon indicating copy to clipboard operation
jless copied to clipboard

[feature request] navigate on the same JSON level

Open a-b opened this issue 2 years ago • 2 comments

I propose to add keymappings that would enable jless user in data mode to move to the next element of the same level. Since J/K are already mapped perhaps gj/gk ?

a-b avatar Jul 23 '22 16:07 a-b

Apologies in advance because my response doesn't contribute to the discussion about this feature, and you may already be aware of this pattern, but: to do something like this I often toggle all the current node's siblings closed using c, first. Then you can easily move up and down among the siblings, and expand either one (right arrow, space bar) or all of them (using e) when I've found the one I want. Doesn't cover all the use-cases that your proposed feature might, but I find it pretty effective most of the time.

bryophyta avatar Aug 07 '22 20:08 bryophyta

How exactly would this differ from the current behavior of J and K?

J and K will move the focus to parent nodes, but jless will "remember" the depth that you are on, so if you have the following JSON file:

{
  "a": [
    1,
    2,
    3
  ],
  "b": [
    4,
    [
      5,
      6
    ],
    7
  ],
  "c": 8
}

which will render in data mode as:

▶ {...}
  ▷ a: [...]
      [0]: 1
      [1]: 2
      [2]: 3
  ▷ b: [...]
      [0]: 4
    ▷ [1]: [...]
        [0]: 5
        [1]: 6
      [2]: 7
  ▷ c: 8

and you navigate to the 2, then hit J multiple times, it will focus the 3, then go "up" in the tree to focus the "b" key, but then go back "down" in the tree and focus the 4, then the opening of the array, then it will skip over 5 and 6, and focus the 7.

PaulJuliusMartinez avatar Jul 17 '23 03:07 PaulJuliusMartinez