@@ -3,8 +3,8 @@ use crate::{Buffer, Rope, RopeSlice, Selection, SelectionRange};
33
44/// A state represents the current editor state of a single buffer.
55pub struct State {
6− doc: Buffer,
7− selection: Selection,
6+ pub(crate) doc: Buffer,
7+ pub(crate) selection: Selection,
88}
99
1010#[derive(Copy, Clone, PartialEq, Eq)]
@@ -59,17 +59,17 @@ impl State {
5959 pos: usize,
6060 dir: Direction,
6161 granularity: Granularity,
62− n: usize,
62+ count: usize,
6363 ) -> usize {
6464 let text = &self.doc.contents;
6565 match (dir, granularity) {
6666 (Direction::Backward, Granularity::Character) => {
67− nth_prev_grapheme_boundary(&text.slice(..), pos, n)
67+ nth_prev_grapheme_boundary(&text.slice(..), pos, count)
6868 }
6969 (Direction::Forward, Granularity::Character) => {
70− nth_next_grapheme_boundary(&text.slice(..), pos, n)
70+ nth_next_grapheme_boundary(&text.slice(..), pos, count)
7171 }
72− (_, Granularity::Line) => move_vertically(&text.slice(..), dir, pos, n),
72+ (_, Granularity::Line) => move_vertically(&text.slice(..), dir, pos, count),
7373 _ => pos,
7474 }
7575 }
@@ -79,7 +79,7 @@ impl State {
7979 sel: Selection,
8080 dir: Direction,
8181 granularity: Granularity,
82− // TODO: n
82+ count: usize,
8383 ) -> Selection {
8484 // TODO: move all selections according to normal cursor move semantics by collapsing it
8585 // into cursors and moving them vertically
@@ -93,7 +93,7 @@ impl State {
9393 // range.to()
9494 // }
9595 // } else {
96− let pos = self.move_pos(range.head, dir, granularity, 1);
96+ let pos = self.move_pos(range.head, dir, granularity, count);
9797 // };
9898 SelectionRange::new(pos, pos)
9999 });
@@ -107,10 +107,10 @@ impl State {
107107 sel: Selection,
108108 dir: Direction,
109109 granularity: Granularity,
110− n: usize,
110+ count: usize,
111111 ) -> Selection {
112112 let ranges = sel.ranges.into_iter().map(|range| {
113− let pos = self.move_pos(range.head, dir, granularity, n);
113+ let pos = self.move_pos(range.head, dir, granularity, count);
114114 SelectionRange::new(range.anchor, pos)
115115 });
116116
@@ -138,7 +138,7 @@ pub fn pos_at_coords(text: &RopeSlice, coords: Coords) -> usize {
138138 nth_next_grapheme_boundary(text, line_start, col)
139139}
140140
141−fn move_vertically(text: &RopeSlice, dir: Direction, pos: usize, n: usize) -> usize {
141+fn move_vertically(text: &RopeSlice, dir: Direction, pos: usize, count: usize) -> usize {
142142 let (line, col) = coords_at_pos(text, pos);
143143
144144 let new_line = match dir {
@@ -159,10 +159,6 @@ fn move_vertically(text: &RopeSlice, dir: Direction, pos: usize, n: usize) -> us
159159 pos_at_coords(text, (new_line, new_col))
160160}
161161
162−/// A command is a function that takes the current state and a count, and does a side-effect on the
163−/// state (usually by creating and applying a transaction).
164−type Command = fn(state: &mut State, count: usize) -> bool;
165−
166162#[cfg(test)]
167163mod test {
168164 use super::*;