Cleanup: use doc.selection() instead of doc.state.selection().

imgbot
Blaž Hrastnik 4 years ago
parent 3445abf88e
commit 1cf887dea9

@ -101,7 +101,7 @@ mod test {
// Need to commit before applying! // Need to commit before applying!
history.commit_revision(&transaction1, &state); history.commit_revision(&transaction1, &state);
transaction1.apply(&mut 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! // Need to commit before applying!
history.commit_revision(&transaction2, &state); history.commit_revision(&transaction2, &state);
transaction2.apply(&mut state); transaction2.apply(&mut state);
assert_eq!("hello 世界!", state.doc()); assert_eq!("hello 世界!", state.doc);
// --- // ---
fn undo(history: &mut History, state: &mut State) { fn undo(history: &mut History, state: &mut State) {
@ -126,15 +126,15 @@ mod test {
} }
undo(&mut history, &mut state); undo(&mut history, &mut state);
assert_eq!("hello world!", state.doc()); assert_eq!("hello world!", state.doc);
redo(&mut history, &mut state); 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);
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 at root is a no-op
undo(&mut history, &mut state); undo(&mut history, &mut state);
assert_eq!("hello", state.doc()); assert_eq!("hello", state.doc);
} }
} }

@ -128,7 +128,6 @@ impl Range {
/// A selection consists of one or more selection ranges. /// A selection consists of one or more selection ranges.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Selection { pub struct Selection {
// TODO: decide how many ranges to inline SmallVec<[Range; 1]>
ranges: SmallVec<[Range; 1]>, ranges: SmallVec<[Range; 1]>,
primary_index: usize, primary_index: usize,
} }

@ -27,22 +27,22 @@ impl State {
pub fn new(doc: Rope) -> Self { pub fn new(doc: Rope) -> Self {
Self { Self {
doc, doc,
selection: Selection::single(0, 0), selection: Selection::point(0),
} }
} }
// TODO: doc/selection accessors // TODO: doc/selection accessors
// TODO: be able to take either Rope or RopeSlice // TODO: be able to take either Rope or RopeSlice
#[inline] // #[inline]
pub fn doc(&self) -> &Rope { // pub fn doc(&self) -> &Rope {
&self.doc // &self.doc
} // }
#[inline] // #[inline]
pub fn selection(&self) -> &Selection { // pub fn selection(&self) -> &Selection {
&self.selection // &self.selection
} // }
// pub fn doc<R>(&self, range: R) -> RopeSlice // pub fn doc<R>(&self, range: R) -> RopeSlice
// where // where

@ -1578,7 +1578,7 @@ fn test_input_edits() {
let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes); let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
transaction.apply(&mut state); transaction.apply(&mut state);
assert_eq!(state.doc(), "fn test(a: u32) {}"); assert_eq!(state.doc, "fn test(a: u32) {}");
assert_eq!( assert_eq!(
edits, edits,
&[InputEdit { &[InputEdit {

@ -443,7 +443,7 @@ impl Transaction {
/// Generate a transaction that reverts this one. /// Generate a transaction that reverts this one.
pub fn invert(&self, original: &State) -> Self { 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 // Store the current cursor position
let selection = original.selection.clone(); let selection = original.selection.clone();

@ -942,7 +942,6 @@ pub fn yank(cx: &mut Context) {
// TODO: should selections be made end inclusive? // TODO: should selections be made end inclusive?
let doc = cx.doc(); let doc = cx.doc();
let values = doc let values = doc
.state
.selection() .selection()
.fragments(doc.text().slice(..)) .fragments(doc.text().slice(..))
.map(|cow| cow.into_owned()) .map(|cow| cow.into_owned())

@ -209,7 +209,6 @@ impl EditorView {
for selection in view for selection in view
.doc .doc
.state
.selection() .selection()
.ranges() .ranges()
.iter() .iter()

@ -36,7 +36,7 @@ impl View {
} }
pub fn ensure_cursor_in_view(&mut self) { 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 line = self.doc.text().char_to_line(cursor);
let document_end = self.first_line + (self.area.height as usize).saturating_sub(2); let document_end = self.first_line + (self.area.height as usize).saturating_sub(2);

Loading…
Cancel
Save