Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add arrow key support #103

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Version 0.7.3

- Fix quote blocks word wrapping.
- Add the arrow keys as aliases for HJKL (#103, by @cmrschwarz)

# Version 0.7.2

Expand Down
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Syntax highlighting](#syntax-highlighting)
- [Configuration](#configuration)
- [Links](#links)
- [Neovim plugin](#neovim-plugin)
- [Contributions](#contributions)

<!--toc:end-->
Expand Down Expand Up @@ -42,24 +43,24 @@ _file tree_.

## Key binds

| Key | Action |
| ---------- | ---------------------------------------------------------------------- |
| `j` | Scroll down |
| `k` | Scroll up |
| `l` | Scroll one page down |
| `h` | Scroll one page up |
| `f` or `/` | Search |
| `n` or `N` | Jump to next or previous search result |
| `s` or `S` | Enter select link mode. Different selection strategy. |
| `Enter` | Select. Depending on which mode it can: open file, select link, search |
| `Esc` | Go back to _normal_ mode |
| `t` | Go back to files |
| `b` | Go back to previous file (file tree if no previous file) |
| `g` | Go to top of file |
| `G` | Go to bottom of the file |
| `d` | Go down half a page |
| `u` | Go up half a page |
| `q` | Quit the application |
| Key | Action |
| ---------------- | ---------------------------------------------------------------------- |
| `j` or `<Down>` | Scroll down |
| `k` or `<Up>` | Scroll up |
| `l` or `<Left>` | Scroll one page down |
| `h` or `<Right>` | Scroll one page up |
| `f` or `/` | Search |
| `n` or `N` | Jump to next or previous search result |
| `s` or `S` | Enter select link mode. Different selection strategy. |
| `<Enter>` | Select. Depending on which mode it can: open file, select link, search |
| `Esc` | Go back to _normal_ mode |
| `t` | Go back to files |
| `b` | Go back to previous file (file tree if no previous file) |
| `g` | Go to top of file |
| `G` | Go to bottom of the file |
| `d` | Go down half a page |
| `u` | Go up half a page |
| `q` | Quit the application |

## Syntax highlighting

Expand Down
24 changes: 12 additions & 12 deletions src/boxes/help_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ fn render_file_tree_help(expanded: bool, area: Rect, buf: &mut Buffer) {
let header = Row::new(vec!["Key", "Action"]);

let key_actions = [
Row::new(vec!["j", "Move down"]),
Row::new(vec!["k", "Move up"]),
Row::new(vec!["h", "Go to previous page"]),
Row::new(vec!["l", "Go to next page"]),
Row::new(vec!["j or <Down>", "Move down"]),
Row::new(vec!["k or <Up>", "Move up"]),
Row::new(vec!["h or <Left>", "Go to previous page"]),
Row::new(vec!["l or <Right>", "Go to next page"]),
Row::new(vec!["g", "Move to top"]),
Row::new(vec!["G", "Move to bottom"]),
Row::new(vec!["/ or f", "Search"]),
Row::new(vec!["Enter", "Open file"]),
Row::new(vec!["<Enter>", "Open file"]),
Row::new(vec!["q", "Quit"]),
];

let widths = [10, 20];
let widths = [12, 20];

let table = Table::new(key_actions, widths).header(header.fg(CONFIG.table_header_fg_color));
table.render(area, buf);
Expand All @@ -81,23 +81,23 @@ fn render_markdown_help(expandend: bool, area: Rect, buf: &mut Buffer) {
let header = Row::new(vec!["Key", "Action"]);

let key_actions = [
Row::new(vec!["j", "Move down"]),
Row::new(vec!["k", "Move up"]),
Row::new(vec!["j or <Down>", "Move down"]),
Row::new(vec!["k or <Up>", "Move up"]),
Row::new(vec!["d", "Move half page down"]),
Row::new(vec!["h", "Move full page up"]),
Row::new(vec!["l", "Move full page down"]),
Row::new(vec!["h or <Left>", "Move full page up"]),
Row::new(vec!["l or <Right>", "Move full page down"]),
Row::new(vec!["u", "Move half page up"]),
Row::new(vec!["G", "Move to bottom"]),
Row::new(vec!["g", "Move to top"]),
Row::new(vec!["/ or f", "Search"]),
Row::new(vec!["b", "Go back to previous file"]),
Row::new(vec!["t", "Toggle file tree"]),
Row::new(vec!["s", "Enter select mode"]),
Row::new(vec!["Enter", "Open link/file"]),
Row::new(vec!["<Enter>", "Open link/file"]),
Row::new(vec!["q", "Quit"]),
];

let widths = [10, 25];
let widths = [12, 25];

let table = Table::new(key_actions, widths).header(header.fg(CONFIG.table_header_fg_color));

Expand Down
16 changes: 8 additions & 8 deletions src/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ pub fn keyboard_mode_file_tree(
_ => {}
},
Boxes::None => match key {
KeyCode::Char('j') => {
KeyCode::Char('j') | KeyCode::Down => {
file_tree.next(height);
}

KeyCode::Char('k') => {
KeyCode::Char('k') | KeyCode::Up => {
file_tree.previous(height);
}

KeyCode::Char('l') => {
KeyCode::Char('l') | KeyCode::Right => {
file_tree.next_page(height);
}

KeyCode::Char('h') => {
KeyCode::Char('h') | KeyCode::Left => {
file_tree.previous_page(height);
}

Expand Down Expand Up @@ -235,7 +235,7 @@ fn keyboard_mode_view(
_ => {}
},
Boxes::None => match key {
KeyCode::Char('j') => {
KeyCode::Char('j') | KeyCode::Down => {
if app.selected {
app.select_index = cmp::min(app.select_index + 1, markdown.num_links() - 1);
app.vertical_scroll = if let Ok(scroll) = markdown.select(app.select_index) {
Expand All @@ -251,7 +251,7 @@ fn keyboard_mode_view(
);
}
}
KeyCode::Char('k') => {
KeyCode::Char('k') | KeyCode::Up => {
if app.selected {
app.select_index = app.select_index.saturating_sub(1);
app.vertical_scroll = if let Ok(scroll) = markdown.select(app.select_index) {
Expand Down Expand Up @@ -282,14 +282,14 @@ fn keyboard_mode_view(
app.vertical_scroll = app.vertical_scroll.saturating_sub(height / 2);
}

KeyCode::Char('l') => {
KeyCode::Char('l') | KeyCode::Right => {
app.vertical_scroll = cmp::min(
app.vertical_scroll + height,
markdown.height().saturating_sub(height / 2),
);
}

KeyCode::Char('h') | KeyCode::Char('K') => {
KeyCode::Char('h') | KeyCode::Left | KeyCode::Char('K') => {
if !app.selected {
app.vertical_scroll = app.vertical_scroll.saturating_sub(height);
} else {
Expand Down