-
Notifications
You must be signed in to change notification settings - Fork 19
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
Implement command mode #90
Comments
I found this line of code in sapling/src/editor/normal_mode.rs Line 33 in 1c57e64
Are we overload the self with our own pointer here?But the self: Box<Self> is immutable.Line 37 in 4786ca4
How can we use the sapling/src/editor/normal_mode.rs Line 40 in 1c57e64
self is a pointer, but you did deref it, is this because self Deref coercion happened here?
|
How can I add |
I think it's
Oh! I hadn't really noticed that |
I tried to add |
Ah yes, apparently you have to put it in the implementation, not the trait - it seems that |
Learned something new, I feel great. |
Cool 😁. To be honest, the current code is incredibly janky and hard to understand - I was doing some unrelated work on Sapling last night and realised a way to make it much easier to understand. Would it cause much chaos if I were to change the type signatures for |
No, go ahead. I haven't done much. |
This is because // before
fn cool_function(mut some_owned_data: SomeCoolType) {}
// after
fn cool_function(some_owned_data: SomeCoolType) {
// here it is shadowed by a mutable binding of the same name
let mut some_owned_data = some_owned_data;
}
// these are both equivalent For EDIT: changing the mutability of a binding is an implementation detail |
To make implementation easier, the different modes in Sapling are implemented as a state machine (technically a DFA). So each 'mode' should have a struct which implements
editor::state::State
(likeeditor::normal_mode::State
).The most useful part of this trait is the 'transition function', which is run every time the user presses a key. It also returns
Box<dyn state::State>
, which allows for state transitions on key presses (i.e. if the user presses:
in normal mode, it should return the default command mode state to enter command mode).So implementing command mode basically boils down to the following:
State
for command mode (would make sense to put it ineditor/command_mode.rs
).:
in normal mode, which switches the editor into command mode (see quitting the editor withq
for how to do this).w
andq
from insert mode into command mode, and if you want you can also add a command to write the.dot
code for theDag
to either the log or a file.If you want more pointers, then just ask 😁 - the state transition code is quite unintuitive.
The text was updated successfully, but these errors were encountered: