Skip to content

Commit

Permalink
v0.7.6: Move to matching bracket with %
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Reiter committed Oct 3, 2024
1 parent c7640e9 commit 2a1060b
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Released
--------

0.7.6 - 03 Okt 2024
===================
- Move to opening/closing bracket with '%'

0.7.5 - 03 Okt 2024
===================
- Highlight search text
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "edtui"
version = "0.7.5"
version = "0.7.6"
edition = "2021"
repository = "https://github.com/preiter93/edtui"
keywords = ["ratatui", "tui", "editor", "text", "vim"]
Expand All @@ -10,7 +10,8 @@ license = "MIT"

[dependencies]
ratatui = "0.28"
jagged = { package = "edtui-jagged", version = "0.1.5" }
# jagged = { package = "edtui-jagged", path="../edtui-jagged", version = "0.1.6" }
jagged = { package = "edtui-jagged", version = "0.1.6" }
enum_dispatch = "0.3.12"
arboard = { version = "3.3.0", optional = true }
arbitrary = { version = "1", optional = true, features = ["derive"] }
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# edtui

### `EdTUI`

#### Overview
Expand Down Expand Up @@ -40,6 +38,7 @@ EditorView::new(&mut state)
| `0` | Move cursor to start of line |
| `^` | Move cursor to first non-blank character |
| `$` | Move cursor to end of line |
| `%` | Move cursor to closing/opening bracket |
| `a` | Append after the cursor |
| `A` | Append at the end of the line |
| `o` | Add a new line below and enter Insert mode |
Expand Down
5 changes: 3 additions & 2 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub use self::cpaste::{CopySelection, Paste};
pub use self::delete::{DeleteChar, DeleteLine, DeleteSelection, RemoveChar};
pub use self::insert::{AppendNewline, InsertChar, InsertNewline, LineBreak};
pub use self::motion::{
MoveBackward, MoveDown, MoveForward, MoveToEnd, MoveToFirst, MoveToStart, MoveUp,
MoveWordBackward, MoveWordForward,
MoveBackward, MoveDown, MoveForward, MoveToEnd, MoveToFirst, MoveToMatchinBracket, MoveToStart,
MoveUp, MoveWordBackward, MoveWordForward,
};
use self::search::StartSearch;
pub use self::search::{
Expand All @@ -37,6 +37,7 @@ pub enum Action {
MoveToStart(MoveToStart),
MoveToFirst(MoveToFirst),
MoveToEnd(MoveToEnd),
MoveToMatchingBracket(MoveToMatchinBracket),
InsertChar(InsertChar),
LineBreak(LineBreak),
AppendNewline(AppendNewline),
Expand Down
12 changes: 12 additions & 0 deletions src/actions/motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,18 @@ impl Execute for MoveToEnd {
}
}

// Move the cursor to the closing bracket.
#[derive(Clone, Debug, Copy)]
pub struct MoveToMatchinBracket();

impl Execute for MoveToMatchinBracket {
fn execute(&mut self, state: &mut EditorState) {
if let Some(index) = state.lines.find_closing_bracket(state.cursor) {
state.cursor = index;
};
}
}

#[cfg(test)]
mod tests {
use crate::{Index2, Lines};
Expand Down
11 changes: 8 additions & 3 deletions src/events/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::actions::search::StartSearch;
use crate::actions::{
Action, Append, AppendCharToSearch, AppendNewline, Composed, CopySelection, DeleteChar,
DeleteLine, DeleteSelection, Execute, FindNext, FindPrevious, InsertChar, InsertNewline,
LineBreak, MoveBackward, MoveDown, MoveForward, MoveToEnd, MoveToFirst, MoveToStart, MoveUp,
MoveWordBackward, MoveWordForward, Paste, Redo, RemoveChar, RemoveCharFromSearch,
SelectBetween, SelectLine, StopSearch, SwitchMode, TriggerSearch, Undo,
LineBreak, MoveBackward, MoveDown, MoveForward, MoveToEnd, MoveToFirst, MoveToMatchinBracket,
MoveToStart, MoveUp, MoveWordBackward, MoveWordForward, Paste, Redo, RemoveChar,
RemoveCharFromSearch, SelectBetween, SelectLine, StopSearch, SwitchMode, TriggerSearch, Undo,
};
use crate::{EditorMode, EditorState};
use ratatui::crossterm::event::{KeyCode, KeyEvent as CTKeyEvent, KeyModifiers};
Expand Down Expand Up @@ -237,6 +237,11 @@ impl Default for KeyEventHandler {
KeyEventRegister::n(vec![KeyEvent::Char('A')]),
Composed::new(MoveToEnd()).chain(Append).into(),
),
// Move cursor to the next opening/closing bracket.
(
KeyEventRegister::n(vec![KeyEvent::Char('%')]),
MoveToMatchinBracket().into(),
),
// Append/insert new line and switch into insert mode
(
KeyEventRegister::n(vec![KeyEvent::Char('o')]),
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
//! | `0` | Move cursor to start of line |
//! | `^` | Move cursor to first non-blank character |
//! | `$` | Move cursor to end of line |
//! | `%` | Move cursor to closing/opening bracket |
//! | `a` | Append after the cursor |
//! | `A` | Append at the end of the line |
//! | `o` | Add a new line below and enter Insert mode |
Expand Down

0 comments on commit 2a1060b

Please sign in to comment.