on master help sign in
Fix build.
commitf8fe273a2e52659f89c82f94fab4b2800518bbea authorBlaž Hrastnik <blaz@mxxn.io> dateMon 8 Jun 2020, 00:31 (6 years ago) parent843c20a
5 files changed+28−26
helix-core/src/commands.rs+15−10 helix-core/src/selection.rs+1 helix-core/src/state.rs+2−2 helix-term/Cargo.toml−4 helix-term/src/keymap.rs+10−10
helix-core/src/commands.rs+15−10
@@ -2,42 +2,47 @@ use crate::state::{Direction, Granularity, State};
22
33/// A command is a function that takes the current state and a count, and does a side-effect on the
44/// state (usually by creating and applying a transaction).
5−type Command = fn(state: &mut State, count: usize);
5+pub type Command = fn(state: &mut State, count: usize);
66
7−fn move_char_left(state: &mut State, count: usize) {
7+pub fn move_char_left(state: &mut State, count: usize) {
88 // TODO: use a transaction
9− state.selection = state.move_selection(
10− state.selection,
9+ let selection = state.move_selection(
10+ // TODO: remove the clone here
11+ state.selection.clone(),
1112 Direction::Backward,
1213 Granularity::Character,
1314 count,
1415 );
16+ state.selection = selection;
1517}
1618
17−fn move_char_right(state: &mut State, count: usize) {
19+pub fn move_char_right(state: &mut State, count: usize) {
1820 // TODO: use a transaction
1921 state.selection = state.move_selection(
20− state.selection,
22+ // TODO: remove the clone here
23+ state.selection.clone(),
2124 Direction::Forward,
2225 Granularity::Character,
2326 count,
2427 );
2528}
2629
27−fn move_line_up(state: &mut State, count: usize) {
30+pub fn move_line_up(state: &mut State, count: usize) {
2831 // TODO: use a transaction
2932 state.selection = state.move_selection(
30− state.selection,
33+ // TODO: remove the clone here
34+ state.selection.clone(),
3135 Direction::Backward,
3236 Granularity::Line,
3337 count,
3438 );
3539}
3640
37−fn move_line_down(state: &mut State, count: usize) {
41+pub fn move_line_down(state: &mut State, count: usize) {
3842 // TODO: use a transaction
3943 state.selection = state.move_selection(
40− state.selection,
44+ // TODO: remove the clone here
45+ state.selection.clone(),
4146 Direction::Forward,
4247 Granularity::Line,
4348 count,
helix-core/src/selection.rs+1
@@ -97,6 +97,7 @@ impl Range {
9797}
9898
9999/// A selection consists of one or more selection ranges.
100+#[derive(Debug, Clone)]
100101pub struct Selection {
101102 // TODO: decide how many ranges to inline SmallVec<[Range; 1]>
102103 pub(crate) ranges: SmallVec<[Range; 1]>,
helix-core/src/state.rs+2−2
@@ -142,8 +142,8 @@ fn move_vertically(text: &RopeSlice, dir: Direction, pos: usize, count: usize) -
142142 let (line, col) = coords_at_pos(text, pos);
143143
144144 let new_line = match dir {
145− Direction::Backward => line.saturating_sub(n),
146− Direction::Forward => std::cmp::min(line.saturating_add(n), text.len_lines() - 1),
145+ Direction::Backward => line.saturating_sub(count),
146+ Direction::Forward => std::cmp::min(line.saturating_add(count), text.len_lines() - 1),
147147 };
148148
149149 // convert to 0-indexed
helix-term/Cargo.toml−4
@@ -10,10 +10,6 @@ edition = "2018"
1010name = "hx"
1111path = "src/main.rs"
1212
13−[[bin]]
14−name = "line"
15−path = "src/line.rs"
16−
1713[dependencies]
1814# termwiz = { git = "https://github.com/wez/wezterm", features = ["widgets"] }
1915# termwiz = { path = "../../wezterm/termwiz", default-features = false, features = ["widgets"] }
helix-term/src/keymap.rs+10−10
@@ -1,4 +1,4 @@
1−use crossterm::event::{KeyEvent as Key, KeyModifiers as Modifiers};
1+use crossterm::event::{KeyCode, KeyEvent as Key, KeyModifiers as Modifiers};
22use helix_core::commands::{self, Command};
33use std::collections::HashMap;
44
@@ -97,20 +97,20 @@ type Keymap = HashMap<Key, Command>;
9797fn default() -> Keymap {
9898 hashmap!(
9999 Key {
100− code: "h",
100+ code: KeyCode::Char('h'),
101101 modifiers: Modifiers::NONE
102− } => commands::move_char_left,
102+ } => commands::move_char_left as Command,
103103 Key {
104− code: "j",
104+ code: KeyCode::Char('j'),
105105 modifiers: Modifiers::NONE
106− } => commands::move_line_down,
106+ } => commands::move_line_down as Command,
107107 Key {
108− code: "k",
108+ code: KeyCode::Char('k'),
109109 modifiers: Modifiers::NONE
110− } => commands::move_line_up,
110+ } => commands::move_line_up as Command,
111111 Key {
112− code: "l",
112+ code: KeyCode::Char('l'),
113113 modifiers: Modifiers::NONE
114− } => commands::move_char_right,
115− );
114+ } => commands::move_char_right as Command,
115+ )
116116}