Skip to content

Commit

Permalink
Merge pull request #33 from ynqa/v0.2.1/wordbreak
Browse files Browse the repository at this point in the history
v0.2.1: enhance keyboard shortcut (word-break)
  • Loading branch information
ynqa committed Mar 29, 2024
2 parents 489421d + e92f5f6 commit 933da62
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 19 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jnv"
version = "0.2.0"
version = "0.2.1"
authors = ["ynqa <[email protected]>"]
edition = "2021"
description = "JSON navigator and interactive filter leveraging jq"
Expand All @@ -10,10 +10,10 @@ readme = "README.md"

[dependencies]
anyhow = "1.0.80"
clap = { version = "4.5.1", features = ["derive"] }
clap = { version = "4.5.4", features = ["derive"] }
gag = "1.0.0"
j9 = "0.1.3"
promkit = "0.3.2"
promkit = "0.3.3"
radix_trie = "0.2.1"

# The profile that 'cargo dist' will build with
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# jnv

[![ci](https://github.com/ynqa/jnv/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/ynqa/jnv/actions/workflows/ci.yml)

*jnv* is designed for navigating JSON,
offering an interactive JSON viewer and `jq` filter editor.

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

## Usage

Expand Down
3 changes: 2 additions & 1 deletion src/jnv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{cell::RefCell, rc::Rc};
use std::{cell::RefCell, collections::HashSet, rc::Rc};

use anyhow::Result;
use gag::Gag;
Expand Down Expand Up @@ -90,6 +90,7 @@ impl Jnv {
active_char_style: StyleBuilder::new().bgc(Color::Magenta).build(),
inactive_char_style: StyleBuilder::new().build(),
edit_mode,
word_break_chars: HashSet::from(['.', '|', '(', ')', '[', ']']),
lines: Default::default(),
},
hint_message_renderer: text::Renderer {
Expand Down
37 changes: 37 additions & 0 deletions src/jnv/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ pub fn default(event: &Event, renderer: &mut crate::jnv::render::Renderer) -> Re
state: KeyEventState::NONE,
}) => query_editor_after_mut.texteditor.move_to_tail(),

Event::Key(KeyEvent {
code: KeyCode::Char('b'),
modifiers: KeyModifiers::ALT,
kind: KeyEventKind::Press,
state: KeyEventState::NONE,
}) => query_editor_after_mut
.texteditor
.move_to_previous_nearest(&query_editor_after_mut.word_break_chars),

Event::Key(KeyEvent {
code: KeyCode::Char('f'),
modifiers: KeyModifiers::ALT,
kind: KeyEventKind::Press,
state: KeyEventState::NONE,
}) => query_editor_after_mut
.texteditor
.move_to_next_nearest(&query_editor_after_mut.word_break_chars),

// Erase char(s).
Event::Key(KeyEvent {
code: KeyCode::Backspace,
Expand All @@ -83,6 +101,25 @@ pub fn default(event: &Event, renderer: &mut crate::jnv::render::Renderer) -> Re
state: KeyEventState::NONE,
}) => query_editor_after_mut.texteditor.erase_all(),

// Erase to the nearest character.
Event::Key(KeyEvent {
code: KeyCode::Char('w'),
modifiers: KeyModifiers::CONTROL,
kind: KeyEventKind::Press,
state: KeyEventState::NONE,
}) => query_editor_after_mut
.texteditor
.erase_to_previous_nearest(&query_editor_after_mut.word_break_chars),

Event::Key(KeyEvent {
code: KeyCode::Char('d'),
modifiers: KeyModifiers::ALT,
kind: KeyEventKind::Press,
state: KeyEventState::NONE,
}) => query_editor_after_mut
.texteditor
.erase_to_next_nearest(&query_editor_after_mut.word_break_chars),

// Move up.
Event::Key(KeyEvent {
code: KeyCode::Up,
Expand Down

0 comments on commit 933da62

Please sign in to comment.