diff options
author | Blaž Hrastnik | 2021-05-07 05:40:11 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-05-07 05:45:49 +0000 |
commit | c20813690f962856efa1989576d9f7c91364f265 (patch) | |
tree | 12291c3defd478536806c369e3520e30b5631018 | |
parent | f2c79e245bdcc70be3c51fdca35917a929615152 (diff) |
View::new is infallible, so is editor.switch/new_file.
-rw-r--r-- | helix-term/src/application.rs | 2 | ||||
-rw-r--r-- | helix-term/src/commands.rs | 4 | ||||
-rw-r--r-- | helix-view/src/editor.rs | 18 | ||||
-rw-r--r-- | helix-view/src/view.rs | 10 |
4 files changed, 14 insertions, 20 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 9838998a..ae7e22bd 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -52,7 +52,7 @@ impl Application { editor.open(file, Action::VerticalSplit)?; } } else { - editor.new_file(Action::VerticalSplit)?; + editor.new_file(Action::VerticalSplit); } compositor.push(Box::new(ui::EditorView::new())); diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 5c1021e1..addd7437 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -935,9 +935,7 @@ pub fn buffer_picker(cx: &mut Context) { }, |editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| { use helix_view::editor::Action; - editor - .switch(*id, Action::Replace) - .expect("editor.open failed"); + editor.switch(*id, Action::Replace); }, ); cx.push_layer(Box::new(picker)); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 256e0e83..435b2b7e 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -66,7 +66,7 @@ impl Editor { } } - pub fn switch(&mut self, id: DocumentId, action: Action) -> Result<DocumentId, Error> { + pub fn switch(&mut self, id: DocumentId, action: Action) { use crate::tree::Layout; use helix_core::Selection; match action { @@ -87,17 +87,17 @@ impl Editor { let doc = &mut self.documents[id]; doc.selections.insert(view_id, Selection::point(0)); - return Ok(id); + return; } Action::HorizontalSplit => { - let view = View::new(id)?; + let view = View::new(id); let view_id = self.tree.split(view, Layout::Horizontal); // initialize selection for view let doc = &mut self.documents[id]; doc.selections.insert(view_id, Selection::point(0)); } Action::VerticalSplit => { - let view = View::new(id)?; + let view = View::new(id); let view_id = self.tree.split(view, Layout::Vertical); // initialize selection for view let doc = &mut self.documents[id]; @@ -106,16 +106,15 @@ impl Editor { } self._refresh(); - - Ok(id) } - pub fn new_file(&mut self, action: Action) -> Result<DocumentId, Error> { + pub fn new_file(&mut self, action: Action) -> DocumentId { use helix_core::Rope; let doc = Document::new(Rope::from("\n")); let id = self.documents.insert(doc); self.documents[id].id = id; - self.switch(id, action) + self.switch(id, action); + id } pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> { @@ -159,7 +158,8 @@ impl Editor { id }; - self.switch(id, action) + self.switch(id, action); + Ok(id) } pub fn close(&mut self, id: ViewId) { diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 5519d9ff..f82de90e 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -1,5 +1,3 @@ -use anyhow::Error; - use std::borrow::Cow; use crate::{Document, DocumentId, ViewId}; @@ -63,17 +61,15 @@ pub struct View { } impl View { - pub fn new(doc: DocumentId) -> Result<Self, Error> { - let view = Self { + pub fn new(doc: DocumentId) -> Self { + Self { id: ViewId::default(), doc, first_line: 0, first_col: 0, area: Rect::default(), // will get calculated upon inserting into tree jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel - }; - - Ok(view) + } } pub fn ensure_cursor_in_view(&mut self, doc: &Document) { |