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

pull/8/head
Blaž Hrastnik 3 years ago
parent 3445abf88e
commit 1cf887dea9

@ -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);
}
}

@ -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,
}

@ -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<R>(&self, range: R) -> RopeSlice
// where

@ -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 {

@ -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();

@ -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())

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

@ -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);

Loading…
Cancel
Save