aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Hrastnik2020-09-25 14:04:58 +0000
committerJan Hrastnik2020-09-25 14:04:58 +0000
commitfbe313779e83728b7dca7925df722c7fb4228d98 (patch)
treeb6303a58eb5bb98e36fb78b9511dcfb1950396ec
parente0785aabe7618d5211f258a058bf08892ff04d06 (diff)
added move_line_start and move_line_end
-rw-r--r--helix-view/src/commands.rs75
-rw-r--r--helix-view/src/keymap.rs8
2 files changed, 49 insertions, 34 deletions
diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs
index be3ea0b9..42390c23 100644
--- a/helix-view/src/commands.rs
+++ b/helix-view/src/commands.rs
@@ -39,6 +39,45 @@ pub fn move_line_down(view: &mut View, count: usize) {
.move_selection(Direction::Forward, Granularity::Line, count);
}
+pub fn move_line_end(view: &mut View, count: usize) {
+ // TODO: use a transaction
+ let lines = selection_lines(&view.state);
+
+ let positions = lines
+ .into_iter()
+ .map(|index| {
+ // adjust all positions to the end of the line.
+ let line = view.state.doc.line(index);
+ let line_start = view.state.doc.line_to_char(index);
+ line_start + line.len_chars() - 1
+ })
+ .map(|pos| Range::new(pos, pos));
+
+ let selection = Selection::new(positions.collect(), 0);
+
+ let transaction = Transaction::new(&mut view.state).with_selection(selection);
+
+ transaction.apply(&mut view.state);
+}
+
+pub fn move_line_start(view: &mut View, count: usize) {
+ let lines = selection_lines(&view.state);
+
+ let positions = lines
+ .into_iter()
+ .map(|index| {
+ // adjust all positions to the start of the line.
+ view.state.doc.line_to_char(index)
+ })
+ .map(|pos| Range::new(pos, pos));
+
+ let selection = Selection::new(positions.collect(), 0);
+
+ let transaction = Transaction::new(&mut view.state).with_selection(selection);
+
+ transaction.apply(&mut view.state);
+}
+
pub fn move_next_word_start(view: &mut View, count: usize) {
let pos = view.state.move_pos(
view.state.selection.cursor(),
@@ -127,46 +166,14 @@ fn selection_lines(state: &State) -> Vec<usize> {
pub fn prepend_to_line(view: &mut View, _count: usize) {
view.state.mode = Mode::Insert;
- let lines = selection_lines(&view.state);
-
- let positions = lines
- .into_iter()
- .map(|index| {
- // adjust all positions to the start of the line.
- view.state.doc.line_to_char(index)
- })
- .map(|pos| Range::new(pos, pos));
-
- let selection = Selection::new(positions.collect(), 0);
-
- let transaction = Transaction::new(&mut view.state).with_selection(selection);
-
- transaction.apply(&mut view.state);
- // TODO: need to store into history if successful
+ move_line_start(view, _count);
}
// A inserts at the end of each line with a selection
pub fn append_to_line(view: &mut View, _count: usize) {
view.state.mode = Mode::Insert;
- let lines = selection_lines(&view.state);
-
- let positions = lines
- .into_iter()
- .map(|index| {
- // adjust all positions to the end of the line.
- let line = view.state.doc.line(index);
- let line_start = view.state.doc.line_to_char(index);
- line_start + line.len_chars() - 1
- })
- .map(|pos| Range::new(pos, pos));
-
- let selection = Selection::new(positions.collect(), 0);
-
- let transaction = Transaction::new(&mut view.state).with_selection(selection);
-
- transaction.apply(&mut view.state);
- // TODO: need to store into history if successful
+ move_line_end(view, _count);
}
// o inserts a new line after each line with a selection
diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs
index 9fabf41d..5d9b6653 100644
--- a/helix-view/src/keymap.rs
+++ b/helix-view/src/keymap.rs
@@ -99,6 +99,14 @@ pub fn default() -> Keymaps {
modifiers: Modifiers::NONE
}] => commands::move_line_up as Command,
vec![Key {
+ code: KeyCode::Char('0'),
+ modifiers: Modifiers::NONE
+ }] => commands::move_line_start as Command,
+ vec![Key {
+ code: KeyCode::Char('$'),
+ modifiers: Modifiers::NONE
+ }] => commands::move_line_end as Command,
+ vec![Key {
code: KeyCode::Char('l'),
modifiers: Modifiers::NONE
}] => commands::move_char_right as Command,