diff options
author | Blaž Hrastnik | 2020-12-03 04:12:40 +0000 |
---|---|---|
committer | GitHub | 2020-12-03 04:12:40 +0000 |
commit | b7a3e525ed7fed5ed79e8580df2e3496bd994419 (patch) | |
tree | d202637047759b0510a16d8c59fdbbde62b50617 /helix-view/src/editor.rs | |
parent | 2e12fc9a7cd221bb7b5f4b5c1ece599089770ccb (diff) | |
parent | 39bf1ca82514e1dc56dfebdce2558cce662367d1 (diff) |
Merge pull request #5 from helix-editor/lsp
LSP: mk1
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r-- | helix-view/src/editor.rs | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index c292caed..9fb2ae36 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1,24 +1,48 @@ -use crate::View; +use crate::theme::Theme; +use crate::{Document, View}; use std::path::PathBuf; use anyhow::Error; pub struct Editor { - pub view: Option<View>, + pub views: Vec<View>, + pub focus: usize, pub should_close: bool, + pub theme: Theme, // TODO: share one instance +} + +impl Default for Editor { + fn default() -> Self { + Self::new() + } } impl Editor { pub fn new() -> Self { + let theme = Theme::default(); + Self { - view: None, + views: Vec::new(), + focus: 0, should_close: false, + theme, } } pub fn open(&mut self, path: PathBuf, size: (u16, u16)) -> Result<(), Error> { - self.view = Some(View::open(path, size)?); + let pos = self.views.len(); + let doc = Document::load(path, self.theme.scopes())?; + self.views.push(View::new(doc, size)?); + self.focus = pos; Ok(()) } + + pub fn view(&self) -> Option<&View> { + self.views.get(self.focus) + } + + pub fn view_mut(&mut self) -> Option<&mut View> { + self.views.get_mut(self.focus) + } } |