From 1cf887dea93f7aa2184772fa2073751f031c5bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Sun, 14 Mar 2021 10:04:03 +0900 Subject: [PATCH] Cleanup: use doc.selection() instead of doc.state.selection(). --- helix-core/src/history.rs | 12 ++++++------ helix-core/src/selection.rs | 1 - helix-core/src/state.rs | 18 +++++++++--------- helix-core/src/syntax.rs | 2 +- helix-core/src/transaction.rs | 2 +- helix-term/src/commands.rs | 1 - helix-term/src/ui/editor.rs | 1 - helix-view/src/view.rs | 2 +- 8 files changed, 18 insertions(+), 21 deletions(-) diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs index 664455251..99de3f7cf 100644 --- a/helix-core/src/history.rs +++ b/helix-core/src/history.rs @@ -101,7 +101,7 @@ mod test { // Need to commit before applying! history.commit_revision(&transaction1, &state); transaction1.apply(&mut state); - assert_eq!("hello world!", state.doc()); + assert_eq!("hello world!", state.doc); // --- @@ -111,7 +111,7 @@ mod test { // Need to commit before applying! history.commit_revision(&transaction2, &state); transaction2.apply(&mut state); - assert_eq!("hello 世界!", state.doc()); + assert_eq!("hello 世界!", state.doc); // --- fn undo(history: &mut History, state: &mut State) { @@ -126,15 +126,15 @@ mod test { } undo(&mut history, &mut state); - assert_eq!("hello world!", state.doc()); + assert_eq!("hello world!", state.doc); redo(&mut history, &mut state); - assert_eq!("hello 世界!", state.doc()); + assert_eq!("hello 世界!", state.doc); undo(&mut history, &mut state); undo(&mut history, &mut state); - assert_eq!("hello", state.doc()); + assert_eq!("hello", state.doc); // undo at root is a no-op undo(&mut history, &mut state); - assert_eq!("hello", state.doc()); + assert_eq!("hello", state.doc); } } diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs index edad81a77..ee925cbc2 100644 --- a/helix-core/src/selection.rs +++ b/helix-core/src/selection.rs @@ -128,7 +128,6 @@ impl Range { /// A selection consists of one or more selection ranges. #[derive(Debug, Clone)] pub struct Selection { - // TODO: decide how many ranges to inline SmallVec<[Range; 1]> ranges: SmallVec<[Range; 1]>, primary_index: usize, } diff --git a/helix-core/src/state.rs b/helix-core/src/state.rs index 8ff86f0c7..b02f9b391 100644 --- a/helix-core/src/state.rs +++ b/helix-core/src/state.rs @@ -27,22 +27,22 @@ impl State { pub fn new(doc: Rope) -> Self { Self { doc, - selection: Selection::single(0, 0), + selection: Selection::point(0), } } // TODO: doc/selection accessors // TODO: be able to take either Rope or RopeSlice - #[inline] - pub fn doc(&self) -> &Rope { - &self.doc - } + // #[inline] + // pub fn doc(&self) -> &Rope { + // &self.doc + // } - #[inline] - pub fn selection(&self) -> &Selection { - &self.selection - } + // #[inline] + // pub fn selection(&self) -> &Selection { + // &self.selection + // } // pub fn doc(&self, range: R) -> RopeSlice // where diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 15fc38c6f..54aa78cfa 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -1578,7 +1578,7 @@ fn test_input_edits() { let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes); transaction.apply(&mut state); - assert_eq!(state.doc(), "fn test(a: u32) {}"); + assert_eq!(state.doc, "fn test(a: u32) {}"); assert_eq!( edits, &[InputEdit { diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs index e12aeebef..bd6053059 100644 --- a/helix-core/src/transaction.rs +++ b/helix-core/src/transaction.rs @@ -443,7 +443,7 @@ impl Transaction { /// Generate a transaction that reverts this one. pub fn invert(&self, original: &State) -> Self { - let changes = self.changes.invert(original.doc()); + let changes = self.changes.invert(&original.doc); // Store the current cursor position let selection = original.selection.clone(); diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index edc38a48a..36edde4c4 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -942,7 +942,6 @@ pub fn yank(cx: &mut Context) { // TODO: should selections be made end inclusive? let doc = cx.doc(); let values = doc - .state .selection() .fragments(doc.text().slice(..)) .map(|cow| cow.into_owned()) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 68f25830a..abdbb7a33 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -209,7 +209,6 @@ impl EditorView { for selection in view .doc - .state .selection() .ranges() .iter() diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 15f0171f8..5b269a9a7 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -36,7 +36,7 @@ impl View { } pub fn ensure_cursor_in_view(&mut self) { - let cursor = self.doc.state.selection().cursor(); + let cursor = self.doc.selection().cursor(); let line = self.doc.text().char_to_line(cursor); let document_end = self.first_line + (self.area.height as usize).saturating_sub(2);