on master help sign in
View::new is infallible, so is editor.switch/new_file.
commitc20813690f962856efa1989576d9f7c91364f265 authorBlaž Hrastnik <blaz@mxxn.io> dateFri 7 May 2021, 14:40 (5 years ago) parentf2c79e2
4 files changed+14−20
helix-term/src/application.rs+1−1 helix-term/src/commands.rs+1−3 helix-view/src/editor.rs+9−9 helix-view/src/view.rs+3−7
helix-term/src/application.rs+1−1
@@ -52,7 +52,7 @@ impl Application {
5252 editor.open(file, Action::VerticalSplit)?;
5353 }
5454 } else {
55− editor.new_file(Action::VerticalSplit)?;
55+ editor.new_file(Action::VerticalSplit);
5656 }
5757
5858 compositor.push(Box::new(ui::EditorView::new()));
helix-term/src/commands.rs+1−3
@@ -935,9 +935,7 @@ pub fn buffer_picker(cx: &mut Context) {
935935 },
936936 |editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
937937 use helix_view::editor::Action;
938− editor
939− .switch(*id, Action::Replace)
940− .expect("editor.open failed");
938+ editor.switch(*id, Action::Replace);
941939 },
942940 );
943941 cx.push_layer(Box::new(picker));
helix-view/src/editor.rs+9−9
@@ -66,7 +66,7 @@ impl Editor {
6666 }
6767 }
6868
69− pub fn switch(&mut self, id: DocumentId, action: Action) -> Result<DocumentId, Error> {
69+ pub fn switch(&mut self, id: DocumentId, action: Action) {
7070 use crate::tree::Layout;
7171 use helix_core::Selection;
7272 match action {
@@ -87,17 +87,17 @@ impl Editor {
8787 let doc = &mut self.documents[id];
8888 doc.selections.insert(view_id, Selection::point(0));
8989
90− return Ok(id);
90+ return;
9191 }
9292 Action::HorizontalSplit => {
93− let view = View::new(id)?;
93+ let view = View::new(id);
9494 let view_id = self.tree.split(view, Layout::Horizontal);
9595 // initialize selection for view
9696 let doc = &mut self.documents[id];
9797 doc.selections.insert(view_id, Selection::point(0));
9898 }
9999 Action::VerticalSplit => {
100− let view = View::new(id)?;
100+ let view = View::new(id);
101101 let view_id = self.tree.split(view, Layout::Vertical);
102102 // initialize selection for view
103103 let doc = &mut self.documents[id];
@@ -106,16 +106,15 @@ impl Editor {
106106 }
107107
108108 self._refresh();
109−
110− Ok(id)
111109 }
112110
113− pub fn new_file(&mut self, action: Action) -> Result<DocumentId, Error> {
111+ pub fn new_file(&mut self, action: Action) -> DocumentId {
114112 use helix_core::Rope;
115113 let doc = Document::new(Rope::from("\n"));
116114 let id = self.documents.insert(doc);
117115 self.documents[id].id = id;
118− self.switch(id, action)
116+ self.switch(id, action);
117+ id
119118 }
120119
121120 pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> {
@@ -159,7 +158,8 @@ impl Editor {
159158 id
160159 };
161160
162− self.switch(id, action)
161+ self.switch(id, action);
162+ Ok(id)
163163 }
164164
165165 pub fn close(&mut self, id: ViewId) {
helix-view/src/view.rs+3−7
@@ -1,5 +1,3 @@
1−use anyhow::Error;
2−
31use std::borrow::Cow;
42
53use crate::{Document, DocumentId, ViewId};
@@ -63,17 +61,15 @@ pub struct View {
6361}
6462
6563impl View {
66− pub fn new(doc: DocumentId) -> Result<Self, Error> {
67− let view = Self {
64+ pub fn new(doc: DocumentId) -> Self {
65+ Self {
6866 id: ViewId::default(),
6967 doc,
7068 first_line: 0,
7169 first_col: 0,
7270 area: Rect::default(), // will get calculated upon inserting into tree
7371 jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel
74− };
75−
76− Ok(view)
72+ }
7773 }
7874
7975 pub fn ensure_cursor_in_view(&mut self, doc: &Document) {