Skip to content

Commit

Permalink
reaftoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacperacy committed May 18, 2024
1 parent c52974f commit 4e9a5f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ impl App {
}
}

fn set_dirty(&mut self) {
pub fn set_dirty(&mut self) {
self.dirty = true;
self.reset_quit();
}

pub fn reset_quit(&mut self) {
self.quit_times = QUIT_TIMES;
}

pub fn insert_char(&mut self, c: char) {
self.set_dirty();

while self.cursor_position.y >= self.content.len() {
self.content.push(String::new());
}
Expand All @@ -82,8 +84,6 @@ impl App {
}

pub fn add_new_line(&mut self) {
self.set_dirty();

while self.cursor_position.y >= self.content.len() {
self.content.push(String::new());
}
Expand All @@ -96,8 +96,6 @@ impl App {
}

pub fn pop_char(&mut self) {
self.set_dirty();

if self.content.len() == 0 {
return;
}
Expand All @@ -116,7 +114,7 @@ impl App {
}

pub fn move_cursor(&mut self, direction: Direction) {
self.quit_times = QUIT_TIMES;
self.reset_quit();

if direction.x < 0 && self.cursor_position.x + self.cursor_offset.x > 0 {
if self.cursor_position.x == 0 {
Expand Down
3 changes: 3 additions & 0 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
}
_ => match key_event.code {
KeyCode::Enter => {
app.set_dirty();
app.add_new_line();
}
KeyCode::Backspace => {
app.set_dirty();
app.pop_char();
}
KeyCode::Left => {
Expand All @@ -29,6 +31,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
}
_ => {
if let KeyCode::Char(c) = key_event.code {
app.set_dirty();
app.insert_char(c)
}
}
Expand Down

0 comments on commit 4e9a5f2

Please sign in to comment.