Skip to content

Commit

Permalink
Merge pull request #54 from pike-text-editor/next-previous-buffer
Browse files Browse the repository at this point in the history
Next previous buffer
  • Loading branch information
jedrzej-grabski authored Jan 2, 2025
2 parents 482f6d8 + 9b9865a commit 2d971c8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
33 changes: 33 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Configuration

The editor is configured using a toml file, by default searched for at `$XDG_CONFIG_HOME/pike/pike.toml`.
You can run pike with `-c/--config [path]` for a custom config path.

### Keymap

Located in the `keymaps` section. The keybinds follow VSCode notation, e.g. `ctrl+shift+p`, `ctrl+alt+del` and
are defined as key-value pairs. Example:

```toml
[keymaps]
"ctrl+s" = "open_file"
"ctrl+y" = "open_file"
```

The following actions are bindable:

| Action | Description | Default | Config definition |
|---------------------------|-------------------------------------------------------------------|--------------------------|----------------------------------|
| Open file | Opens a popup where a relative path should be inserted | ctrl+o | "open_file" |
| Open new buffer | Creates a new, empty buffer not bound to a file for editing | ctrl+n | "new_buffer" |
| Switch to next buffer | Moves focus to the next buffer in the list | ctrl+h | "next_buffer" |
| Switch to previous buffer | Moves focus to the previous buffer in the list | ctrl+l | "previous_buffer" |
| Search in current buffer | Searches for a specific term within the currently active buffer | ctrl+f | "search_in_current_buffer" |
| Replace in current buffer | Replaces text within the current buffer based on a search query | ctrl+j | "replace_in_current_buffer" |
| Save changes | Saves the current buffer to its associated file | ctrl+s | "save" |
| Undo last change | Reverts the most recent change in the current buffer | ctrl+z | "undo" |
| Redo last change | Reapplies the most recently undone change in the current buffer | ctrl+y | "redo" |
| Quit | Closes the application | ctrl+q | "quit" |

Keybindings which contain multiple modifiers are not yet supported and will be added
in the future (<https://docs.rs/crossterm/latest/crossterm/event/struct.KeyboardEnhancementFlags.html>).
30 changes: 12 additions & 18 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ impl Default for Config {
Operation::CreateNewBuffer,
),
(
KeyShortcut::new(KeyCode::Tab, KeyModifiers::CONTROL),
KeyShortcut::new(KeyCode::Char('h'), KeyModifiers::CONTROL),
Operation::SwitchToNextBuffer,
),
(
KeyShortcut::new(KeyCode::Tab, KeyModifiers::SHIFT | KeyModifiers::CONTROL),
KeyShortcut::new(KeyCode::Char('l'), KeyModifiers::CONTROL),
Operation::SwitchToPreviousBuffer,
),
(
Expand All @@ -142,18 +142,15 @@ impl Default for Config {
Operation::SearchInCurrentBuffer,
),
(
KeyShortcut::new(KeyCode::Char('h'), KeyModifiers::CONTROL),
KeyShortcut::new(KeyCode::Char('j'), KeyModifiers::CONTROL),
Operation::SearchAndReplaceInCurrentBuffer,
),
(
KeyShortcut::new(KeyCode::Char('z'), KeyModifiers::CONTROL),
Operation::Undo,
),
(
KeyShortcut::new(
KeyCode::Char('z'),
KeyModifiers::SHIFT | KeyModifiers::CONTROL,
),
KeyShortcut::new(KeyCode::Char('y'), KeyModifiers::CONTROL),
Operation::Redo,
),
(
Expand Down Expand Up @@ -208,16 +205,20 @@ mod config_test {
),
Operation::OpenFile,
),
(
KeyShortcut::new(KeyCode::Char('s'), KeyModifiers::CONTROL),
Operation::SaveBufferToFile,
),
(
KeyShortcut::new(KeyCode::Char('n'), KeyModifiers::CONTROL),
Operation::CreateNewBuffer,
),
(
KeyShortcut::new(KeyCode::Tab, KeyModifiers::CONTROL),
KeyShortcut::new(KeyCode::Char('h'), KeyModifiers::CONTROL),
Operation::SwitchToNextBuffer,
),
(
KeyShortcut::new(KeyCode::Tab, KeyModifiers::SHIFT | KeyModifiers::CONTROL),
KeyShortcut::new(KeyCode::Char('l'), KeyModifiers::CONTROL),
Operation::SwitchToPreviousBuffer,
),
(
Expand All @@ -229,22 +230,15 @@ mod config_test {
Operation::SearchInCurrentBuffer,
),
(
KeyShortcut::new(KeyCode::Char('h'), KeyModifiers::CONTROL),
KeyShortcut::new(KeyCode::Char('j'), KeyModifiers::CONTROL),
Operation::SearchAndReplaceInCurrentBuffer,
),
(
KeyShortcut::new(KeyCode::Char('s'), KeyModifiers::CONTROL),
Operation::SaveBufferToFile,
),
(
KeyShortcut::new(KeyCode::Char('z'), KeyModifiers::CONTROL),
Operation::Undo,
),
(
KeyShortcut::new(
KeyCode::Char('z'),
KeyModifiers::SHIFT | KeyModifiers::CONTROL,
),
KeyShortcut::new(KeyCode::Char('y'), KeyModifiers::CONTROL),
Operation::Redo,
),
(
Expand Down
8 changes: 4 additions & 4 deletions src/pike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ impl Pike {
}

/// Switch to the previous buffer
fn previous_buffer(&mut self) {
todo!()
pub fn previous_buffer(&mut self) {
self.workspace.previous_buffer();
}

/// Switch to the next buffer
fn next_buffer(&mut self) {
todo!()
pub fn next_buffer(&mut self) {
self.workspace.next_buffer();
}

/// Search for a query in the current buffer and return
Expand Down

0 comments on commit 2d971c8

Please sign in to comment.