aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/editor.rs9
-rw-r--r--helix-view/src/lib.rs1
-rw-r--r--helix-view/src/view.rs16
3 files changed, 16 insertions, 10 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 08fd1f0c..61abd482 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -1,4 +1,6 @@
+use crate::theme::Theme;
use crate::View;
+use helix_core::State;
use std::path::PathBuf;
@@ -8,20 +10,25 @@ pub struct Editor {
pub views: Vec<View>,
pub focus: usize,
pub should_close: bool,
+ pub theme: Theme, // TODO: share one instance
}
impl Editor {
pub fn new() -> Self {
+ let theme = Theme::default();
+
Self {
views: Vec::new(),
focus: 0,
should_close: false,
+ theme,
}
}
pub fn open(&mut self, path: PathBuf, size: (u16, u16)) -> Result<(), Error> {
let pos = self.views.len();
- self.views.push(View::open(path, size)?);
+ let state = State::load(path, self.theme.scopes())?;
+ self.views.push(View::new(state, size)?);
self.focus = pos;
Ok(())
}
diff --git a/helix-view/src/lib.rs b/helix-view/src/lib.rs
index 8ea634af..9abe8a1a 100644
--- a/helix-view/src/lib.rs
+++ b/helix-view/src/lib.rs
@@ -6,4 +6,5 @@ pub mod theme;
pub mod view;
pub use editor::Editor;
+pub use theme::Theme;
pub use view::View;
diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs
index 2b68dbc3..d2a7d556 100644
--- a/helix-view/src/view.rs
+++ b/helix-view/src/view.rs
@@ -1,8 +1,7 @@
use anyhow::Error;
-use std::{borrow::Cow, path::PathBuf};
+use std::borrow::Cow;
-use crate::theme::Theme;
use helix_core::{
graphemes::{grapheme_width, RopeGraphemes},
indent::TAB_WIDTH,
@@ -12,24 +11,23 @@ use tui::layout::Rect;
pub const PADDING: usize = 5;
+// TODO: view should be View { doc: Document(state, history,..) }
+// since we can have multiple views into the same file
pub struct View {
pub state: State,
- pub history: History,
pub first_line: usize,
pub size: (u16, u16),
- pub theme: Theme, // TODO: share one instance
+
+ // TODO: Doc<> fields
+ pub history: History,
}
impl View {
- pub fn open(path: PathBuf, size: (u16, u16)) -> Result<Self, Error> {
- let theme = Theme::default();
- let state = State::load(path, theme.scopes())?;
-
+ pub fn new(state: State, size: (u16, u16)) -> Result<Self, Error> {
let view = Self {
state,
first_line: 0,
size,
- theme,
history: History::default(),
};