Add a entering Insert mode with appending cursor instead #2

Merged
mars merged 6 commits from emma/breed:append into main 2023-04-11 21:48:30 +00:00
Contributor
No description provided.
emma added 2 commits 2023-04-11 20:55:49 +00:00
mars requested changes 2023-04-11 20:58:25 +00:00
mars left a comment
Owner

You don't need a new mode for append.

You don't need a new mode for append.
src/main.rs Outdated
@ -189,1 +192,4 @@
}
KeyCode::Char('a') => {
self.move_cursor(Direction::Right);
self.mode = Mode::Append;
Owner

None of the new Mode::Append code is necessary if you just set self.mode to Mode::Insert instead.

None of the new `Mode::Append` code is necessary if you just set `self.mode` to `Mode::Insert` instead.
Author
Contributor

Okay, then what is the best way to pass the fact that we pressed a instead of i in on_normal_event() to on_insert_event() so i can tell it to move the cursor back when it re-enters Mode::Normal?

Okay, then what is the best way to pass the fact that we pressed `a` instead of `i` in `on_normal_event()` to `on_insert_event()` so i can tell it to move the cursor back when it re-enters `Mode::Normal`?
Owner

We can give the Mode::Insert variant some data. Let's make a new struct named InsertState which contains a boolean field named append, then add it to Mode::Insert. Then, on_insert_event() can be modified to take a mutable reference to InsertState as an argument. on_event() will match that inner InsertState data on Insert then pass it to on_insert_data(). Exiting insert mode in on_insert_event() can check the flag to see if it should move the cursor back or not.

We can give the `Mode::Insert` variant some data. Let's make a new struct named `InsertState` which contains a boolean field named `append`, then add it to `Mode::Insert`. Then, `on_insert_event()` can be modified to take a mutable reference to `InsertState` as an argument. `on_event()` will match that inner `InsertState` data on `Insert` then pass it to `on_insert_data()`. Exiting insert mode in `on_insert_event()` can check the flag to see if it should move the cursor back or not.
emma added 1 commit 2023-04-11 21:06:17 +00:00
emma added 1 commit 2023-04-11 21:28:51 +00:00
emma requested review from mars 2023-04-11 21:28:55 +00:00
emma added 1 commit 2023-04-11 21:34:56 +00:00
mars approved these changes 2023-04-11 21:47:37 +00:00
mars added 1 commit 2023-04-11 21:48:22 +00:00
mars merged commit 7821969324 into main 2023-04-11 21:48:30 +00:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mars/breed#2
No description provided.