on master help sign in
Fix build.
f8fe273Blaž Hrastnik
helix-core/src/commands.rs+15−10
@@ -2,42 +2,47 @@ use crate::state::{Direction, Granularity, State};
2
2
3/// A command is a function that takes the current state and a count, and does a side-effect on the
3/// A command is a function that takes the current state and a count, and does a side-effect on the
4/// state (usually by creating and applying a transaction).
4/// 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);
6
6
7−fn move_char_left(state: &mut State, count: usize) {
7+pub fn move_char_left(state: &mut State, count: usize) {
8 // TODO: use a transaction
8 // TODO: use a transaction
9− state.selection = state.move_selection(
9+ let selection = state.move_selection(
10+ // TODO: remove the clone here
10− state.selection,
11+ state.selection.clone(),
11 Direction::Backward,
12 Direction::Backward,
12 Granularity::Character,
13 Granularity::Character,
13 count,
14 count,
14 );
15 );
16+ state.selection = selection;
15}
17}
16
18
17−fn move_char_right(state: &mut State, count: usize) {
19+pub fn move_char_right(state: &mut State, count: usize) {
18 // TODO: use a transaction
20 // TODO: use a transaction
19 state.selection = state.move_selection(
21 state.selection = state.move_selection(
22+ // TODO: remove the clone here
20− state.selection,
23+ state.selection.clone(),
21 Direction::Forward,
24 Direction::Forward,
22 Granularity::Character,
25 Granularity::Character,
23 count,
26 count,
24 );
27 );
25}
28}
26
29
27−fn move_line_up(state: &mut State, count: usize) {
30+pub fn move_line_up(state: &mut State, count: usize) {
28 // TODO: use a transaction
31 // TODO: use a transaction
29 state.selection = state.move_selection(
32 state.selection = state.move_selection(
33+ // TODO: remove the clone here
30− state.selection,
34+ state.selection.clone(),
31 Direction::Backward,
35 Direction::Backward,
32 Granularity::Line,
36 Granularity::Line,
33 count,
37 count,
34 );
38 );
35}
39}
36
40
37−fn move_line_down(state: &mut State, count: usize) {
41+pub fn move_line_down(state: &mut State, count: usize) {
38 // TODO: use a transaction
42 // TODO: use a transaction
39 state.selection = state.move_selection(
43 state.selection = state.move_selection(
44+ // TODO: remove the clone here
40− state.selection,
45+ state.selection.clone(),
41 Direction::Forward,
46 Direction::Forward,
42 Granularity::Line,
47 Granularity::Line,
43 count,
48 count,
helix-core/src/selection.rs+1
@@ -97,6 +97,7 @@ impl Range {
97}
97}
98
98
99/// A selection consists of one or more selection ranges.
99/// A selection consists of one or more selection ranges.
100+#[derive(Debug, Clone)]
100pub struct Selection {
101pub struct Selection {
101 // TODO: decide how many ranges to inline SmallVec<[Range; 1]>
102 // TODO: decide how many ranges to inline SmallVec<[Range; 1]>
102 pub(crate) ranges: SmallVec<[Range; 1]>,
103 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) -
142 let (line, col) = coords_at_pos(text, pos);
142 let (line, col) = coords_at_pos(text, pos);
143
143
144 let new_line = match dir {
144 let new_line = match dir {
145− Direction::Backward => line.saturating_sub(n),
145+ Direction::Backward => line.saturating_sub(count),
146− Direction::Forward => std::cmp::min(line.saturating_add(n), text.len_lines() - 1),
146+ Direction::Forward => std::cmp::min(line.saturating_add(count), text.len_lines() - 1),
147 };
147 };
148
148
149 // convert to 0-indexed
149 // convert to 0-indexed
helix-term/Cargo.toml−4
@@ -10,10 +10,6 @@ edition = "2018"
10name = "hx"
10name = "hx"
11path = "src/main.rs"
11path = "src/main.rs"
12
12
13−[[bin]]
14−name = "line"
15−path = "src/line.rs"
16−
17[dependencies]
13[dependencies]
18# termwiz = { git = "https://github.com/wez/wezterm", features = ["widgets"] }
14# termwiz = { git = "https://github.com/wez/wezterm", features = ["widgets"] }
19# termwiz = { path = "../../wezterm/termwiz", default-features = false, features = ["widgets"] }
15# 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};
2use helix_core::commands::{self, Command};
2use helix_core::commands::{self, Command};
3use std::collections::HashMap;
3use std::collections::HashMap;
4
4
@@ -97,20 +97,20 @@ type Keymap = HashMap<Key, Command>;
97fn default() -> Keymap {
97fn default() -> Keymap {
98 hashmap!(
98 hashmap!(
99 Key {
99 Key {
100− code: "h",
100+ code: KeyCode::Char('h'),
101 modifiers: Modifiers::NONE
101 modifiers: Modifiers::NONE
102− } => commands::move_char_left,
102+ } => commands::move_char_left as Command,
103 Key {
103 Key {
104− code: "j",
104+ code: KeyCode::Char('j'),
105 modifiers: Modifiers::NONE
105 modifiers: Modifiers::NONE
106− } => commands::move_line_down,
106+ } => commands::move_line_down as Command,
107 Key {
107 Key {
108− code: "k",
108+ code: KeyCode::Char('k'),
109 modifiers: Modifiers::NONE
109 modifiers: Modifiers::NONE
110− } => commands::move_line_up,
110+ } => commands::move_line_up as Command,
111 Key {
111 Key {
112− code: "l",
112+ code: KeyCode::Char('l'),
113 modifiers: Modifiers::NONE
113 modifiers: Modifiers::NONE
114− } => commands::move_char_right,
114+ } => commands::move_char_right as Command,
115− );
115+ )
116}
116}