Skip to content

Commit

Permalink
add ctrl+up, ctrl+down for treeview navigation
Browse files Browse the repository at this point in the history
- ctrl+up snaps to parent of current node
- ctrl+down snaps to last direct child of current node
  • Loading branch information
molsonkiko committed Dec 8, 2023
1 parent 9328eb5 commit ff053d8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
6. Right-click dropdown menu in [error form](/docs/README.md#error-form-and-status-bar), allowing export of errors to JSON or refreshing the form.
7. The parser is now much better at recovering when an object is missing its closing `'}'` or an array is missing its closing `']'`.
8. Support for [JSON Schema validation](/docs/README.md#validating-json-against-json-schema) of `enum` keyword where the `type` is missing or an array.
9. `Ctrl+Up` now snaps to parent of currently selected node in tree view. `Ctrl+Down` now snaps to the last direct child of the currently selected node.

### Changed

Expand Down
23 changes: 23 additions & 0 deletions JsonToolsNppPlugin/Forms/TreeViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,29 @@ private void TreeViewer_KeyUp(object sender, KeyEventArgs e)
while ((next == null) || (!next.TabStop)) next = GetNextControl(next, !e.Shift);
next.Focus();
}
else if (sender is TreeView && e.Control)
{
// Ctrl+Up -> snap up to parent of current node
if (e.KeyCode == Keys.Up)
{
TreeNode selected = Tree.SelectedNode;
TreeNode parent = selected.Parent;
if (parent is null)
return;
Tree.SelectedNode = parent;
}
// Ctrl+Down -> snap to last child of current node
else if (e.KeyCode == Keys.Down)
{
TreeNode selected = Tree.SelectedNode;
if (selected.Nodes.Count > 0)
{
if (!selected.IsExpanded)
selected.Expand();
Tree.SelectedNode = selected.Nodes[selected.GetNodeCount(false) - 1];
}
}
}
}

private void QueryBox_KeyPress(object sender, KeyPressEventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions JsonToolsNppPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("5.8.0.15")]
[assembly: AssemblyFileVersion("5.8.0.15")]
[assembly: AssemblyVersion("5.8.0.16")]
[assembly: AssemblyFileVersion("5.8.0.16")]
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ __NOTES__
- `Ctrl+Enter` in the query box submits the query.
- `Enter` while the tree is selected toggles the selected node between expanded/collapsed.
- Up and down arrow keys can also navigate the tree.
- `Ctrl+Up` while in the tree selects the parent of the currently selected node. *Added in [v6.0](/CHANGELOG.md#600---unreleased-2023-mm-dd).*
- `Ctrl+Down` while in the tree selects the last direct child of the currently selected node. *Added in [v6.0](/CHANGELOG.md#600---unreleased-2023-mm-dd).*
- `Escape` takes focus from the tree view back to the editor.
5. Beginning in [v4.4.0](/CHANGELOG.md#440---2022-11-23), you can have multiple tree views open.

Expand Down

0 comments on commit ff053d8

Please sign in to comment.