Skip to content
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

moved insert keymap to keymap.rs #1

Merged
merged 2 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions helix-term/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,29 +320,20 @@ impl Editor {
if let Some(view) = &mut self.view {
match view.state.mode() {
Mode::Insert => {
match event {
KeyEvent {
code: KeyCode::Esc, ..
} => commands::normal_mode(view, 1),
KeyEvent {
code: KeyCode::Backspace,
..
} => commands::delete_char_backward(view, 1),
KeyEvent {
code: KeyCode::Delete,
..
} => commands::delete_char_forward(view, 1),
KeyEvent {
// TODO: handle modes and sequences (`gg`)
let keys = vec![event];
if let Some(command) = keymap[&Mode::Insert].get(&keys) {
// TODO: handle count other than 1
command(view, 1);
} else {
if let KeyEvent {
code: KeyCode::Char(c),
..
} => commands::insert_char(view, c),
KeyEvent {
code: KeyCode::Enter,
..
} => commands::insert_char(view, '\n'),
_ => (), // skip
} = event
{
commands::insert_char(view, c);
}
}
// TODO: simplistic ensure cursor in view for now
view.ensure_cursor_in_view();

self.render();
Expand Down
1 change: 1 addition & 0 deletions helix-view/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2018"

[features]
term = ["tui", "crossterm"]
default = ["term"]

[dependencies]
anyhow = "1"
Expand Down
4 changes: 4 additions & 0 deletions helix-view/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ pub fn insert_char(view: &mut View, c: char) {
// TODO: need to store into history if successful
}

pub fn insert_newline(view: &mut View, _count: usize) {
insert_char(view, '\n');
}

// TODO: handle indent-aware delete
pub fn delete_char_backward(view: &mut View, count: usize) {
let text = &view.state.doc.slice(..);
Expand Down
18 changes: 18 additions & 0 deletions helix-view/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,24 @@ pub fn default() -> Keymaps {
code: KeyCode::Esc,
modifiers: Modifiers::NONE
}] => commands::normal_mode as Command,
),
state::Mode::Insert => hashmap!(
vec![Key {
code: KeyCode::Esc,
modifiers: Modifiers::NONE
}] => commands::normal_mode as Command,
vec![Key {
code: KeyCode::Backspace,
modifiers: Modifiers::NONE
}] => commands::delete_char_backward as Command,
vec![Key {
code: KeyCode::Delete,
modifiers: Modifiers::NONE
}] => commands::delete_char_forward as Command,
vec![Key {
code: KeyCode::Enter,
modifiers: Modifiers::NONE
}] => commands::insert_newline as Command,
)
)
}