From 087ff28d0d78471c48a2947f35083f28990c7274 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 22 Oct 2021 09:56:47 +0200 Subject: [PATCH] Move SelectionSet and Into impl to selection module --- crates/buffer/src/lib.rs | 17 ----------------- crates/buffer/src/selection.rs | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/crates/buffer/src/lib.rs b/crates/buffer/src/lib.rs index a5771ad4c0..eec7da424b 100644 --- a/crates/buffer/src/lib.rs +++ b/crates/buffer/src/lib.rs @@ -73,12 +73,6 @@ pub struct Buffer { lamport_clock: clock::Lamport, } -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct SelectionSet { - pub selections: Arc<[Selection]>, - pub active: bool, -} - #[derive(Clone, Debug)] pub struct Transaction { start: clock::Global, @@ -2248,17 +2242,6 @@ impl<'a> Into for &'a Anchor { } } -impl<'a> Into for &'a Selection { - fn into(self) -> proto::Selection { - proto::Selection { - id: self.id as u64, - start: Some((&self.start).into()), - end: Some((&self.end).into()), - reversed: self.reversed, - } - } -} - impl TryFrom for Operation { type Error = anyhow::Error; diff --git a/crates/buffer/src/selection.rs b/crates/buffer/src/selection.rs index 98f34865f5..df0834b67f 100644 --- a/crates/buffer/src/selection.rs +++ b/crates/buffer/src/selection.rs @@ -1,5 +1,7 @@ +use rpc::proto; + use crate::{Anchor, Buffer, Point, ToOffset as _, ToPoint as _}; -use std::{cmp::Ordering, mem, ops::Range}; +use std::{cmp::Ordering, mem, ops::Range, sync::Arc}; pub type SelectionSetId = clock::Lamport; pub type SelectionsVersion = usize; @@ -20,6 +22,12 @@ pub struct Selection { pub goal: SelectionGoal, } +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct SelectionSet { + pub selections: Arc<[Selection]>, + pub active: bool, +} + impl Selection { pub fn head(&self) -> &Anchor { if self.reversed { @@ -73,3 +81,14 @@ impl Selection { } } } + +impl<'a> Into for &'a Selection { + fn into(self) -> proto::Selection { + proto::Selection { + id: self.id as u64, + start: Some((&self.start).into()), + end: Some((&self.end).into()), + reversed: self.reversed, + } + } +}