on master help sign in
Cleanup: use doc.selection() instead of doc.state.selection().
commit1cf887dea93f7aa2184772fa2073751f031c5bf3 authorBlaž Hrastnik <blaz@mxxn.io> dateSun 14 Mar 2021, 10:04 (6 years ago) parent3445abf
8 files changed+18−21
helix-core/src/history.rs+6−6 helix-core/src/selection.rs−1 helix-core/src/state.rs+9−9 helix-core/src/syntax.rs+1−1 helix-core/src/transaction.rs+1−1 helix-term/src/commands.rs−1 helix-term/src/ui/editor.rs−1 helix-view/src/view.rs+1−1
helix-core/src/history.rs+6−6
@@ -101,7 +101,7 @@ mod test {
101101 // Need to commit before applying!
102102 history.commit_revision(&transaction1, &state);
103103 transaction1.apply(&mut state);
104− assert_eq!("hello world!", state.doc());
104+ assert_eq!("hello world!", state.doc);
105105
106106 // ---
107107
@@ -111,7 +111,7 @@ mod test {
111111 // Need to commit before applying!
112112 history.commit_revision(&transaction2, &state);
113113 transaction2.apply(&mut state);
114− assert_eq!("hello 世界!", state.doc());
114+ assert_eq!("hello 世界!", state.doc);
115115
116116 // ---
117117 fn undo(history: &mut History, state: &mut State) {
@@ -126,15 +126,15 @@ mod test {
126126 }
127127
128128 undo(&mut history, &mut state);
129− assert_eq!("hello world!", state.doc());
129+ assert_eq!("hello world!", state.doc);
130130 redo(&mut history, &mut state);
131− assert_eq!("hello 世界!", state.doc());
131+ assert_eq!("hello 世界!", state.doc);
132132 undo(&mut history, &mut state);
133133 undo(&mut history, &mut state);
134− assert_eq!("hello", state.doc());
134+ assert_eq!("hello", state.doc);
135135
136136 // undo at root is a no-op
137137 undo(&mut history, &mut state);
138− assert_eq!("hello", state.doc());
138+ assert_eq!("hello", state.doc);
139139 }
140140}
helix-core/src/selection.rs−1
@@ -128,7 +128,6 @@ impl Range {
128128/// A selection consists of one or more selection ranges.
129129#[derive(Debug, Clone)]
130130pub struct Selection {
131− // TODO: decide how many ranges to inline SmallVec<[Range; 1]>
132131 ranges: SmallVec<[Range; 1]>,
133132 primary_index: usize,
134133}
helix-core/src/state.rs+9−9
@@ -27,22 +27,22 @@ impl State {
2727 pub fn new(doc: Rope) -> Self {
2828 Self {
2929 doc,
30− selection: Selection::single(0, 0),
30+ selection: Selection::point(0),
3131 }
3232 }
3333
3434 // TODO: doc/selection accessors
3535
3636 // TODO: be able to take either Rope or RopeSlice
37− #[inline]
38− pub fn doc(&self) -> &Rope {
39− &self.doc
40− }
37+ // #[inline]
38+ // pub fn doc(&self) -> &Rope {
39+ // &self.doc
40+ // }
4141
42− #[inline]
43− pub fn selection(&self) -> &Selection {
44− &self.selection
45− }
42+ // #[inline]
43+ // pub fn selection(&self) -> &Selection {
44+ // &self.selection
45+ // }
4646
4747 // pub fn doc<R>(&self, range: R) -> RopeSlice
4848 // where
helix-core/src/syntax.rs+1−1
@@ -1578,7 +1578,7 @@ fn test_input_edits() {
15781578 let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
15791579 transaction.apply(&mut state);
15801580
1581− assert_eq!(state.doc(), "fn test(a: u32) {}");
1581+ assert_eq!(state.doc, "fn test(a: u32) {}");
15821582 assert_eq!(
15831583 edits,
15841584 &[InputEdit {
helix-core/src/transaction.rs+1−1
@@ -443,7 +443,7 @@ impl Transaction {
443443
444444 /// Generate a transaction that reverts this one.
445445 pub fn invert(&self, original: &State) -> Self {
446− let changes = self.changes.invert(original.doc());
446+ let changes = self.changes.invert(&original.doc);
447447 // Store the current cursor position
448448 let selection = original.selection.clone();
449449
helix-term/src/commands.rs−1
@@ -942,7 +942,6 @@ pub fn yank(cx: &mut Context) {
942942 // TODO: should selections be made end inclusive?
943943 let doc = cx.doc();
944944 let values = doc
945− .state
946945 .selection()
947946 .fragments(doc.text().slice(..))
948947 .map(|cow| cow.into_owned())
helix-term/src/ui/editor.rs−1
@@ -209,7 +209,6 @@ impl EditorView {
209209
210210 for selection in view
211211 .doc
212− .state
213212 .selection()
214213 .ranges()
215214 .iter()
helix-view/src/view.rs+1−1
@@ -36,7 +36,7 @@ impl View {
3636 }
3737
3838 pub fn ensure_cursor_in_view(&mut self) {
39− let cursor = self.doc.state.selection().cursor();
39+ let cursor = self.doc.selection().cursor();
4040 let line = self.doc.text().char_to_line(cursor);
4141 let document_end = self.first_line + (self.area.height as usize).saturating_sub(2);
4242