@@ -3,8 +3,8 @@ use crate::{Buffer, Rope, RopeSlice, Selection, SelectionRange};
4/// A state represents the current editor state of a single buffer.
4/// A state represents the current editor state of a single buffer.
5pub struct State {
5pub struct State {
6− doc: Buffer,
6+ pub(crate) doc: Buffer,
7− selection: Selection,
7+ pub(crate) selection: Selection,
10#[derive(Copy, Clone, PartialEq, Eq)]
10#[derive(Copy, Clone, PartialEq, Eq)]
@@ -59,17 +59,17 @@ impl State {
59 pos: usize,
59 pos: usize,
60 dir: Direction,
60 dir: Direction,
61 granularity: Granularity,
61 granularity: Granularity,
62− n: usize,
62+ count: usize,
63 ) -> usize {
63 ) -> usize {
64 let text = &self.doc.contents;
64 let text = &self.doc.contents;
65 match (dir, granularity) {
65 match (dir, granularity) {
66 (Direction::Backward, Granularity::Character) => {
66 (Direction::Backward, Granularity::Character) => {
67− nth_prev_grapheme_boundary(&text.slice(..), pos, n)
67+ nth_prev_grapheme_boundary(&text.slice(..), pos, count)
69 (Direction::Forward, Granularity::Character) => {
69 (Direction::Forward, Granularity::Character) => {
70− nth_next_grapheme_boundary(&text.slice(..), pos, n)
70+ nth_next_grapheme_boundary(&text.slice(..), pos, count)
72− (_, Granularity::Line) => move_vertically(&text.slice(..), dir, pos, n),
72+ (_, Granularity::Line) => move_vertically(&text.slice(..), dir, pos, count),
@@ -79,7 +79,7 @@ impl State {
79 sel: Selection,
79 sel: Selection,
80 dir: Direction,
80 dir: Direction,
81 granularity: Granularity,
81 granularity: Granularity,
82− // TODO: n
82+ count: usize,
83 ) -> Selection {
83 ) -> Selection {
84 // TODO: move all selections according to normal cursor move semantics by collapsing it
84 // TODO: move all selections according to normal cursor move semantics by collapsing it
85 // into cursors and moving them vertically
85 // into cursors and moving them vertically
@@ -93,7 +93,7 @@ impl State {
93 // range.to()
93 // range.to()
95 // } else {
95 // } else {
96− let pos = self.move_pos(range.head, dir, granularity, 1);
96+ let pos = self.move_pos(range.head, dir, granularity, count);
98 SelectionRange::new(pos, pos)
98 SelectionRange::new(pos, pos)
@@ -107,10 +107,10 @@ impl State {
107 sel: Selection,
107 sel: Selection,
108 dir: Direction,
108 dir: Direction,
109 granularity: Granularity,
109 granularity: Granularity,
110− n: usize,
110+ count: usize,
111 ) -> Selection {
111 ) -> Selection {
112 let ranges = sel.ranges.into_iter().map(|range| {
112 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);
114 SelectionRange::new(range.anchor, pos)
114 SelectionRange::new(range.anchor, pos)
@@ -138,7 +138,7 @@ pub fn pos_at_coords(text: &RopeSlice, coords: Coords) -> usize {
138 nth_next_grapheme_boundary(text, line_start, col)
138 nth_next_grapheme_boundary(text, line_start, col)
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 {
142 let (line, col) = coords_at_pos(text, pos);
142 let (line, col) = coords_at_pos(text, pos);
144 let new_line = match dir {
144 let new_line = match dir {
@@ -159,10 +159,6 @@ fn move_vertically(text: &RopeSlice, dir: Direction, pos: usize, n: usize) -> us
159 pos_at_coords(text, (new_line, new_col))
159 pos_at_coords(text, (new_line, new_col))
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;
166#[cfg(test)]
162#[cfg(test)]
167mod test {
163mod test {
168 use super::*;
164 use super::*;