aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-09-14 10:50:46 +0000
committerBlaž Hrastnik2020-09-14 10:50:46 +0000
commit31999d6528b247e223774d1a4edec7966dda3d9e (patch)
treefd14e9c223695a6f3fc3d67fbaf543014c6ce9a3 /helix-core
parent96db02742e85648e4ce0c2ab9b7cd239bdb763f8 (diff)
Make state fields read-only from outside the crate.
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/state.rs32
1 files changed, 28 insertions, 4 deletions
diff --git a/helix-core/src/state.rs b/helix-core/src/state.rs
index be2b3317..e41ee565 100644
--- a/helix-core/src/state.rs
+++ b/helix-core/src/state.rs
@@ -4,6 +4,7 @@ use anyhow::Error;
use std::path::PathBuf;
+#[derive(Copy, Clone)]
pub enum Mode {
Normal,
Insert,
@@ -12,10 +13,10 @@ pub enum Mode {
/// A state represents the current editor state of a single buffer.
pub struct State {
/// Path to file on disk.
- pub path: Option<PathBuf>,
- pub doc: Rope,
- pub selection: Selection,
- pub mode: Mode,
+ pub(crate) path: Option<PathBuf>,
+ pub(crate) doc: Rope,
+ pub(crate) selection: Selection,
+ pub(crate) mode: Mode,
}
#[derive(Copy, Clone, PartialEq, Eq)]
@@ -58,6 +59,29 @@ impl State {
// TODO: doc/selection accessors
+ // TODO: be able to take either Rope or RopeSlice
+ #[inline]
+ pub fn doc(&self) -> &Rope {
+ &self.doc
+ }
+
+ #[inline]
+ pub fn selection(&self) -> &Selection {
+ &self.selection
+ }
+
+ #[inline]
+ pub fn mode(&self) -> Mode {
+ self.mode
+ }
+
+ // pub fn doc<R>(&self, range: R) -> RopeSlice
+ // where
+ // R: std::ops::RangeBounds<usize>,
+ // {
+ // self.doc.slice(range)
+ // }
+
// update/transact:
// update(desc) => transaction ? transaction.doc() for applied doc
// transaction.apply(doc)