Skip to content

Commit

Permalink
word break related operation
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Mar 26, 2024
1 parent c3f53a3 commit b876dde
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
13 changes: 6 additions & 7 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ anyhow = "1.0.80"
clap = { version = "4.5.1", features = ["derive"] }
gag = "1.0.0"
j9 = "0.1.3"
promkit = "0.3.2"
# promkit = "0.3.2"
promkit = { git = "https://github.com/ynqa/promkit", branch = "dev-0.3.3/main" }
radix_trie = "0.2.1"

# The profile that 'cargo dist' will build with
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,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 @@ -83,6 +83,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 b876dde

Please sign in to comment.