Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lcagustini committed Oct 1, 2018
1 parent 72625ec commit 91c8459
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn main() {
'running: loop {
for event in event_pump.poll_iter() {
match event {
Event::Quit {..} | Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
Event::Quit {..} => {
break 'running
},

Expand Down Expand Up @@ -93,13 +93,18 @@ fn main() {
nfd::Response::Okay(file_path) => {
text.raw = utils::read_file(&file_path).split("\n").map(|x| x.to_owned()).collect();
text.file_path = file_path;

cursor.x = 0;
cursor.y = 0;

undo_handler.clear_states();
undo_handler.create_state(&cursor, &text);

text.needs_update = true;
},

_ => ()
}
cursor.x = 0;
cursor.y = 0;
text.needs_update = true;
}
},

Expand All @@ -114,6 +119,7 @@ fn main() {
nfd::Response::Okay(file_path) => {
utils::save_file(&file_path, &text.raw);
text.file_path = file_path;

text.needs_update = true;
},

Expand Down
5 changes: 5 additions & 0 deletions src/undo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ impl UndoHandler {
self.cur_state += 1;
}

pub fn clear_states(&mut self) {
self.cur_state = 0;
self.states.clear();
}

pub fn restore_previous_state(&mut self, cursor: &mut cursor::Cursor, text: &mut text::Text) {
if self.cur_state > 0 {
self.cur_state -= 1;
Expand Down

0 comments on commit 91c8459

Please sign in to comment.