aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/commands.rs12
-rw-r--r--helix-view/src/keymap.rs2
-rw-r--r--helix-view/src/view.rs4
3 files changed, 17 insertions, 1 deletions
diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs
index 18135f0f..c92b33f5 100644
--- a/helix-view/src/commands.rs
+++ b/helix-view/src/commands.rs
@@ -417,3 +417,15 @@ pub fn delete_char_forward(view: &mut View, count: usize) {
transaction.apply(&mut view.state);
// TODO: need to store into history if successful
}
+
+// Undo / Redo
+
+pub fn undo(view: &mut View, _count: usize) {
+ view.history.undo(&mut view.state);
+
+ // TODO: each command should simply return a Option<transaction>, then the higher level handles storing it?
+}
+
+pub fn redo(view: &mut View, _count: usize) {
+ view.history.redo(&mut view.state);
+}
diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs
index 72fc0e79..e108324e 100644
--- a/helix-view/src/keymap.rs
+++ b/helix-view/src/keymap.rs
@@ -145,6 +145,8 @@ pub fn default() -> Keymaps {
vec![key!('c')] => commands::change_selection,
vec![key!('s')] => commands::split_selection_on_newline,
vec![key!(';')] => commands::collapse_selection,
+ vec![key!('u')] => commands::undo,
+ vec![shift!('U')] => commands::redo,
vec![Key {
code: KeyCode::Esc,
modifiers: Modifiers::NONE
diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs
index 887c45a2..732c5081 100644
--- a/helix-view/src/view.rs
+++ b/helix-view/src/view.rs
@@ -5,12 +5,13 @@ use std::{borrow::Cow, path::PathBuf};
use crate::theme::Theme;
use helix_core::{
graphemes::{grapheme_width, RopeGraphemes},
- Position, RopeSlice, State,
+ History, Position, RopeSlice, State,
};
use tui::layout::Rect;
pub struct View {
pub state: State,
+ pub history: History,
pub first_line: usize,
pub size: (u16, u16),
pub theme: Theme, // TODO: share one instance
@@ -26,6 +27,7 @@ impl View {
first_line: 0,
size, // TODO: pass in from term
theme,
+ history: History::default(),
};
Ok(view)