on master help sign in
Cleanup: use doc.selection() instead of doc.state.selection().
1cf887dBlaž Hrastnik
helix-core/src/history.rs+6−6
@@ -101,7 +101,7 @@ mod test {
101 // Need to commit before applying!
101 // Need to commit before applying!
102 history.commit_revision(&transaction1, &state);
102 history.commit_revision(&transaction1, &state);
103 transaction1.apply(&mut state);
103 transaction1.apply(&mut state);
104− assert_eq!("hello world!", state.doc());
104+ assert_eq!("hello world!", state.doc);
105
105
106 // ---
106 // ---
107
107
@@ -111,7 +111,7 @@ mod test {
111 // Need to commit before applying!
111 // Need to commit before applying!
112 history.commit_revision(&transaction2, &state);
112 history.commit_revision(&transaction2, &state);
113 transaction2.apply(&mut state);
113 transaction2.apply(&mut state);
114− assert_eq!("hello 世界!", state.doc());
114+ assert_eq!("hello 世界!", state.doc);
115
115
116 // ---
116 // ---
117 fn undo(history: &mut History, state: &mut State) {
117 fn undo(history: &mut History, state: &mut State) {
@@ -126,15 +126,15 @@ mod test {
126 }
126 }
127
127
128 undo(&mut history, &mut state);
128 undo(&mut history, &mut state);
129− assert_eq!("hello world!", state.doc());
129+ assert_eq!("hello world!", state.doc);
130 redo(&mut history, &mut state);
130 redo(&mut history, &mut state);
131− assert_eq!("hello 世界!", state.doc());
131+ assert_eq!("hello 世界!", state.doc);
132 undo(&mut history, &mut state);
132 undo(&mut history, &mut state);
133 undo(&mut history, &mut state);
133 undo(&mut history, &mut state);
134− assert_eq!("hello", state.doc());
134+ assert_eq!("hello", state.doc);
135
135
136 // undo at root is a no-op
136 // undo at root is a no-op
137 undo(&mut history, &mut state);
137 undo(&mut history, &mut state);
138− assert_eq!("hello", state.doc());
138+ assert_eq!("hello", state.doc);
139 }
139 }
140}
140}
helix-core/src/selection.rs−1
@@ -128,7 +128,6 @@ impl Range {
128/// A selection consists of one or more selection ranges.
128/// A selection consists of one or more selection ranges.
129#[derive(Debug, Clone)]
129#[derive(Debug, Clone)]
130pub struct Selection {
130pub struct Selection {
131− // TODO: decide how many ranges to inline SmallVec<[Range; 1]>
132 ranges: SmallVec<[Range; 1]>,
131 ranges: SmallVec<[Range; 1]>,
133 primary_index: usize,
132 primary_index: usize,
134}
133}
helix-core/src/state.rs+9−9
@@ -27,22 +27,22 @@ impl State {
27 pub fn new(doc: Rope) -> Self {
27 pub fn new(doc: Rope) -> Self {
28 Self {
28 Self {
29 doc,
29 doc,
30− selection: Selection::single(0, 0),
30+ selection: Selection::point(0),
31 }
31 }
32 }
32 }
33
33
34 // TODO: doc/selection accessors
34 // TODO: doc/selection accessors
35
35
36 // TODO: be able to take either Rope or RopeSlice
36 // TODO: be able to take either Rope or RopeSlice
37− #[inline]
37+ // #[inline]
38− pub fn doc(&self) -> &Rope {
38+ // pub fn doc(&self) -> &Rope {
39− &self.doc
39+ // &self.doc
40− }
40+ // }
41
41
42− #[inline]
42+ // #[inline]
43− pub fn selection(&self) -> &Selection {
43+ // pub fn selection(&self) -> &Selection {
44− &self.selection
44+ // &self.selection
45− }
45+ // }
46
46
47 // pub fn doc<R>(&self, range: R) -> RopeSlice
47 // pub fn doc<R>(&self, range: R) -> RopeSlice
48 // where
48 // where
helix-core/src/syntax.rs+1−1
@@ -1578,7 +1578,7 @@ fn test_input_edits() {
1578 let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
1578 let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
1579 transaction.apply(&mut state);
1579 transaction.apply(&mut state);
1580
1580
1581− assert_eq!(state.doc(), "fn test(a: u32) {}");
1581+ assert_eq!(state.doc, "fn test(a: u32) {}");
1582 assert_eq!(
1582 assert_eq!(
1583 edits,
1583 edits,
1584 &[InputEdit {
1584 &[InputEdit {
helix-core/src/transaction.rs+1−1
@@ -443,7 +443,7 @@ impl Transaction {
443
443
444 /// Generate a transaction that reverts this one.
444 /// Generate a transaction that reverts this one.
445 pub fn invert(&self, original: &State) -> Self {
445 pub fn invert(&self, original: &State) -> Self {
446− let changes = self.changes.invert(original.doc());
446+ let changes = self.changes.invert(&original.doc);
447 // Store the current cursor position
447 // Store the current cursor position
448 let selection = original.selection.clone();
448 let selection = original.selection.clone();
449
449
helix-term/src/commands.rs−1
@@ -942,7 +942,6 @@ pub fn yank(cx: &mut Context) {
942 // TODO: should selections be made end inclusive?
942 // TODO: should selections be made end inclusive?
943 let doc = cx.doc();
943 let doc = cx.doc();
944 let values = doc
944 let values = doc
945− .state
946 .selection()
945 .selection()
947 .fragments(doc.text().slice(..))
946 .fragments(doc.text().slice(..))
948 .map(|cow| cow.into_owned())
947 .map(|cow| cow.into_owned())
helix-term/src/ui/editor.rs−1
@@ -209,7 +209,6 @@ impl EditorView {
209
209
210 for selection in view
210 for selection in view
211 .doc
211 .doc
212− .state
213 .selection()
212 .selection()
214 .ranges()
213 .ranges()
215 .iter()
214 .iter()
helix-view/src/view.rs+1−1
@@ -36,7 +36,7 @@ impl View {
36 }
36 }
37
37
38 pub fn ensure_cursor_in_view(&mut self) {
38 pub fn ensure_cursor_in_view(&mut self) {
39− let cursor = self.doc.state.selection().cursor();
39+ let cursor = self.doc.selection().cursor();
40 let line = self.doc.text().char_to_line(cursor);
40 let line = self.doc.text().char_to_line(cursor);
41 let document_end = self.first_line + (self.area.height as usize).saturating_sub(2);
41 let document_end = self.first_line + (self.area.height as usize).saturating_sub(2);
42
42