Skip to content

Commit 933da62

Browse files
authored
Merge pull request #33 from ynqa/v0.2.1/wordbreak
v0.2.1: enhance keyboard shortcut (word-break)
2 parents 489421d + e92f5f6 commit 933da62

File tree

5 files changed

+63
-19
lines changed

5 files changed

+63
-19
lines changed

Cargo.lock

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "jnv"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
authors = ["ynqa <[email protected]>"]
55
edition = "2021"
66
description = "JSON navigator and interactive filter leveraging jq"
@@ -10,10 +10,10 @@ readme = "README.md"
1010

1111
[dependencies]
1212
anyhow = "1.0.80"
13-
clap = { version = "4.5.1", features = ["derive"] }
13+
clap = { version = "4.5.4", features = ["derive"] }
1414
gag = "1.0.0"
1515
j9 = "0.1.3"
16-
promkit = "0.3.2"
16+
promkit = "0.3.3"
1717
radix_trie = "0.2.1"
1818

1919
# The profile that 'cargo dist' will build with

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# jnv
22

3+
[![ci](https://github.com/ynqa/jnv/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/ynqa/jnv/actions/workflows/ci.yml)
4+
35
*jnv* is designed for navigating JSON,
46
offering an interactive JSON viewer and `jq` filter editor.
57

@@ -87,6 +89,10 @@ jnv data.json
8789
| <kbd>Enter</kbd> | Toggle expand/collapse in JSON viewer
8890
| <kbd>Ctrl + P</kbd> | Expand all folds in JSON viewer
8991
| <kbd>Ctrl + N</kbd> | Collapse all folds in JSON viewer
92+
| <kbd>Alt + B</kbd> | Move the cursor to the previous nearest character within set(`.`,`\|`,`(`,`)`,`[`,`]`)
93+
| <kbd>Alt + F</kbd> | Move the cursor to the next nearest character within set(`.`,`\|`,`(`,`)`,`[`,`]`)
94+
| <kbd>Ctrl + W</kbd> | Erase to the previous nearest character within set(`.`,`\|`,`(`,`)`,`[`,`]`)
95+
| <kbd>Alt + D</kbd> | Erase to the next nearest character within set(`.`,`\|`,`(`,`)`,`[`,`]`)
9096

9197
## Usage
9298

src/jnv.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{cell::RefCell, rc::Rc};
1+
use std::{cell::RefCell, collections::HashSet, rc::Rc};
22

33
use anyhow::Result;
44
use gag::Gag;
@@ -90,6 +90,7 @@ impl Jnv {
9090
active_char_style: StyleBuilder::new().bgc(Color::Magenta).build(),
9191
inactive_char_style: StyleBuilder::new().build(),
9292
edit_mode,
93+
word_break_chars: HashSet::from(['.', '|', '(', ')', '[', ']']),
9394
lines: Default::default(),
9495
},
9596
hint_message_renderer: text::Renderer {

src/jnv/keymap.rs

+37
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ pub fn default(event: &Event, renderer: &mut crate::jnv::render::Renderer) -> Re
6969
state: KeyEventState::NONE,
7070
}) => query_editor_after_mut.texteditor.move_to_tail(),
7171

72+
Event::Key(KeyEvent {
73+
code: KeyCode::Char('b'),
74+
modifiers: KeyModifiers::ALT,
75+
kind: KeyEventKind::Press,
76+
state: KeyEventState::NONE,
77+
}) => query_editor_after_mut
78+
.texteditor
79+
.move_to_previous_nearest(&query_editor_after_mut.word_break_chars),
80+
81+
Event::Key(KeyEvent {
82+
code: KeyCode::Char('f'),
83+
modifiers: KeyModifiers::ALT,
84+
kind: KeyEventKind::Press,
85+
state: KeyEventState::NONE,
86+
}) => query_editor_after_mut
87+
.texteditor
88+
.move_to_next_nearest(&query_editor_after_mut.word_break_chars),
89+
7290
// Erase char(s).
7391
Event::Key(KeyEvent {
7492
code: KeyCode::Backspace,
@@ -83,6 +101,25 @@ pub fn default(event: &Event, renderer: &mut crate::jnv::render::Renderer) -> Re
83101
state: KeyEventState::NONE,
84102
}) => query_editor_after_mut.texteditor.erase_all(),
85103

104+
// Erase to the nearest character.
105+
Event::Key(KeyEvent {
106+
code: KeyCode::Char('w'),
107+
modifiers: KeyModifiers::CONTROL,
108+
kind: KeyEventKind::Press,
109+
state: KeyEventState::NONE,
110+
}) => query_editor_after_mut
111+
.texteditor
112+
.erase_to_previous_nearest(&query_editor_after_mut.word_break_chars),
113+
114+
Event::Key(KeyEvent {
115+
code: KeyCode::Char('d'),
116+
modifiers: KeyModifiers::ALT,
117+
kind: KeyEventKind::Press,
118+
state: KeyEventState::NONE,
119+
}) => query_editor_after_mut
120+
.texteditor
121+
.erase_to_next_nearest(&query_editor_after_mut.word_break_chars),
122+
86123
// Move up.
87124
Event::Key(KeyEvent {
88125
code: KeyCode::Up,

0 commit comments

Comments
 (0)