Skip to content

Commit

Permalink
selection p2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacperacy committed Jun 23, 2024
1 parent e9acd05 commit 1d19151
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
20 changes: 12 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct App {
prompt_cursor_position: Position,
pub status: String,
pub line_numbers_width: usize,
pub is_selecting: bool,
pub selecting_position: Position,
}

impl Default for App {
Expand All @@ -55,6 +57,8 @@ impl Default for App {
prompt_cursor_position: Position { x: 0, y: 0 },
status: DEFAULT_STATUS.into(),
line_numbers_width: 4,
is_selecting: false,
selecting_position: Position { x: 0, y: 0 },
}
}
}
Expand Down Expand Up @@ -160,7 +164,7 @@ impl App {
pub fn insert_char(&mut self, c: char) {
if self.is_prompt {
self.prompt.insert(self.cursor_position.x, c);
self.move_cursor(Direction { x: 1, y: 0 });
self.move_cursor(Direction { x: 1, y: 0 }, false);
return;
}

Expand All @@ -170,7 +174,7 @@ impl App {

self.content[self.cursor_position.y + self.cursor_offset.y]
.insert_at(self.cursor_position.x + self.cursor_offset.x, c);
self.move_cursor(Direction { x: 1, y: 0 });
self.move_cursor(Direction { x: 1, y: 0 }, false);
}

pub fn add_new_line(&mut self) {
Expand Down Expand Up @@ -198,7 +202,7 @@ impl App {
}

self.cursor_position.x = 0;
self.move_cursor(Direction { x: 0, y: -1 });
self.move_cursor(Direction { x: 0, y: -1 }, false);
}

pub fn pop_char(&mut self) {
Expand All @@ -207,7 +211,7 @@ impl App {
return;
}
self.prompt.pop();
self.move_cursor(Direction { x: -1, y: 0 });
self.move_cursor(Direction { x: -1, y: 0 }, false);
return;
}

Expand All @@ -220,23 +224,23 @@ impl App {
if self.content[pos.y].len() == 0 {
self.remove_from_content(pos.y);

self.move_cursor(Direction { x: 0, y: 1 });
self.move_cursor(Direction { x: 0, y: 1 }, false);
} else if self.cursor_position.x == 0 && self.cursor_position.y > 0 {
let lower_line = self.remove_from_content(pos.y);

self.cursor_position.x = self.content[pos.y - 1].len();

self.content[pos.y - 1].push_str(&lower_line);

self.move_cursor(Direction { x: 0, y: 1 });
self.move_cursor(Direction { x: 0, y: 1 }, false);
} else if !(self.cursor_position.x == 0 && self.cursor_position.y == 0) {
self.content[pos.y].remove_at(pos.x - 1);

self.move_cursor(Direction { x: -1, y: 0 });
self.move_cursor(Direction { x: -1, y: 0 }, false);
}
}

pub fn move_cursor(&mut self, direction: Direction) {
pub fn move_cursor(&mut self, direction: Direction, is_selection: bool) {
self.reset_quit();

if self.is_prompt {
Expand Down
8 changes: 4 additions & 4 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
app.pop_char();
}
KeyCode::Left => {
app.move_cursor(Direction { x: -1, y: 0 });
app.move_cursor(Direction { x: -1, y: 0 }, false);
}
KeyCode::Right => {
app.move_cursor(Direction { x: 1, y: 0 });
app.move_cursor(Direction { x: 1, y: 0 }, false);
}
KeyCode::Up => {
app.move_cursor(Direction { x: 0, y: 1 });
app.move_cursor(Direction { x: 0, y: 1 }, false);
}
KeyCode::Down => {
app.move_cursor(Direction { x: 0, y: -1 });
app.move_cursor(Direction { x: 0, y: -1 }, false);
}
_ => {
if let KeyCode::Char(c) = key_event.code {
Expand Down

0 comments on commit 1d19151

Please sign in to comment.