-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separation of concerns #19
Comments
Also, shouldn't the state be in |
Just finished a refactor that should make this a bit cleaner. The separation of the command handling and the actual editor state manipulation is deliberate. It's a classic three tier architecture. |
I understand the separation, I just think it could've been done better. Lines 8 to 14 in b2c4723
Here's a more complete representation of the editor's state: type Position = usize;
struct State {
edit: Edit,
foot: Option<Foot>,
}
enum Foot {
Message(String),
Prompt(String, Edit),
}
struct Edit {
text: Text,
cursor: Position,
selection: Option<Selection>,
record: Record,
}
struct Selection {
// the selection ends at the cursor position
origin: Position,
active: bool,
} The Line 20 in 819160a
pub fn handle<T>(event: Event, state: State) -> Option<State> Then, the view should take the state and draw the editor, when it is called here: Line 51 in 819160a
|
Ah yes, putting it like that I can see what you mean. There's good reason for the mode state machine to live in
I would disagree with that however. Coupling mode behavior to specific inputs is a bad idea. Maybe in the future we'll want to alter the selection through the keyboard, or at least not by holding a button. |
You're right, I updated my suggestion. |
State::Exit
is not really a possible state.
Are you working on this or should I? |
I though about it a little bit but I'm busy with other stuff at the moment. If you want to do the refactor go for it. |
See
src/command/mod.rs
. One problem is that in its signature thetreat_event
function acceptsState::Exit
, but in the implementation it causes it to panic. I suggest removing theExit
variant and thattreat_event
return anOption<State>
.The text was updated successfully, but these errors were encountered: