helix-mods/helix-view/src/editor.rs

37 lines
723 B
Rust
Raw Normal View History

use crate::View;
use std::path::PathBuf;
use anyhow::Error;
pub struct Editor {
2020-10-19 09:20:59 +02:00
pub views: Vec<View>,
pub focus: usize,
2020-10-16 07:37:12 +02:00
pub should_close: bool,
}
impl Editor {
pub fn new() -> Self {
2020-10-16 07:37:12 +02:00
Self {
2020-10-19 09:20:59 +02:00
views: Vec::new(),
focus: 0,
2020-10-16 07:37:12 +02:00
should_close: false,
}
}
pub fn open(&mut self, path: PathBuf, size: (u16, u16)) -> Result<(), Error> {
2020-10-19 09:20:59 +02:00
let pos = self.views.len();
self.views.push(View::open(path, size)?);
self.focus = pos;
Ok(())
}
2020-10-19 09:20:59 +02:00
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)
}
}