From b2b3083a623ec3dc5e2d1ea9c6ba35970efe19a3 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 19 Oct 2020 16:20:59 +0900 Subject: Support multiple open views. --- helix-view/src/editor.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'helix-view') diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index c292caed..08fd1f0c 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -5,20 +5,32 @@ use std::path::PathBuf; use anyhow::Error; pub struct Editor { - pub view: Option, + pub views: Vec, + pub focus: usize, pub should_close: bool, } impl Editor { pub fn new() -> Self { Self { - view: None, + views: Vec::new(), + focus: 0, should_close: false, } } pub fn open(&mut self, path: PathBuf, size: (u16, u16)) -> Result<(), Error> { - self.view = Some(View::open(path, size)?); + let pos = self.views.len(); + self.views.push(View::open(path, 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) + } } -- cgit v1.2.3-70-g09d2