on master help sign in
View::new is infallible, so is editor.switch/new_file.
c208136Blaž Hrastnik
helix-term/src/application.rs+1−1
@@ -52,7 +52,7 @@ impl Application {
52 editor.open(file, Action::VerticalSplit)?;
52 editor.open(file, Action::VerticalSplit)?;
53 }
53 }
54 } else {
54 } else {
55− editor.new_file(Action::VerticalSplit)?;
55+ editor.new_file(Action::VerticalSplit);
56 }
56 }
57
57
58 compositor.push(Box::new(ui::EditorView::new()));
58 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) {
935 },
935 },
936 |editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
936 |editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
937 use helix_view::editor::Action;
937 use helix_view::editor::Action;
938− editor
939− .switch(*id, Action::Replace)
938+ editor.switch(*id, Action::Replace);
940− .expect("editor.open failed");
941 },
939 },
942 );
940 );
943 cx.push_layer(Box::new(picker));
941 cx.push_layer(Box::new(picker));
helix-view/src/editor.rs+9−9
@@ -66,7 +66,7 @@ impl Editor {
66 }
66 }
67 }
67 }
68
68
69− pub fn switch(&mut self, id: DocumentId, action: Action) -> Result<DocumentId, Error> {
69+ pub fn switch(&mut self, id: DocumentId, action: Action) {
70 use crate::tree::Layout;
70 use crate::tree::Layout;
71 use helix_core::Selection;
71 use helix_core::Selection;
72 match action {
72 match action {
@@ -87,17 +87,17 @@ impl Editor {
87 let doc = &mut self.documents[id];
87 let doc = &mut self.documents[id];
88 doc.selections.insert(view_id, Selection::point(0));
88 doc.selections.insert(view_id, Selection::point(0));
89
89
90− return Ok(id);
90+ return;
91 }
91 }
92 Action::HorizontalSplit => {
92 Action::HorizontalSplit => {
93− let view = View::new(id)?;
93+ let view = View::new(id);
94 let view_id = self.tree.split(view, Layout::Horizontal);
94 let view_id = self.tree.split(view, Layout::Horizontal);
95 // initialize selection for view
95 // initialize selection for view
96 let doc = &mut self.documents[id];
96 let doc = &mut self.documents[id];
97 doc.selections.insert(view_id, Selection::point(0));
97 doc.selections.insert(view_id, Selection::point(0));
98 }
98 }
99 Action::VerticalSplit => {
99 Action::VerticalSplit => {
100− let view = View::new(id)?;
100+ let view = View::new(id);
101 let view_id = self.tree.split(view, Layout::Vertical);
101 let view_id = self.tree.split(view, Layout::Vertical);
102 // initialize selection for view
102 // initialize selection for view
103 let doc = &mut self.documents[id];
103 let doc = &mut self.documents[id];
@@ -106,16 +106,15 @@ impl Editor {
106 }
106 }
107
107
108 self._refresh();
108 self._refresh();
109−
110− Ok(id)
111 }
109 }
112
110
113− pub fn new_file(&mut self, action: Action) -> Result<DocumentId, Error> {
111+ pub fn new_file(&mut self, action: Action) -> DocumentId {
114 use helix_core::Rope;
112 use helix_core::Rope;
115 let doc = Document::new(Rope::from("\n"));
113 let doc = Document::new(Rope::from("\n"));
116 let id = self.documents.insert(doc);
114 let id = self.documents.insert(doc);
117 self.documents[id].id = id;
115 self.documents[id].id = id;
118− self.switch(id, action)
116+ self.switch(id, action);
117+ id
119 }
118 }
120
119
121 pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> {
120 pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> {
@@ -159,7 +158,8 @@ impl Editor {
159 id
158 id
160 };
159 };
161
160
162− self.switch(id, action)
161+ self.switch(id, action);
162+ Ok(id)
163 }
163 }
164
164
165 pub fn close(&mut self, id: ViewId) {
165 pub fn close(&mut self, id: ViewId) {
helix-view/src/view.rs+3−7
@@ -1,5 +1,3 @@
1−use anyhow::Error;
2−
3use std::borrow::Cow;
1use std::borrow::Cow;
4
2
5use crate::{Document, DocumentId, ViewId};
3use crate::{Document, DocumentId, ViewId};
@@ -63,17 +61,15 @@ pub struct View {
63}
61}
64
62
65impl View {
63impl View {
66− pub fn new(doc: DocumentId) -> Result<Self, Error> {
64+ pub fn new(doc: DocumentId) -> Self {
67− let view = Self {
65+ Self {
68 id: ViewId::default(),
66 id: ViewId::default(),
69 doc,
67 doc,
70 first_line: 0,
68 first_line: 0,
71 first_col: 0,
69 first_col: 0,
72 area: Rect::default(), // will get calculated upon inserting into tree
70 area: Rect::default(), // will get calculated upon inserting into tree
73 jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel
71 jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel
74− };
72+ }
75−
76− Ok(view)
77 }
73 }
78
74
79 pub fn ensure_cursor_in_view(&mut self, doc: &Document) {
75 pub fn ensure_cursor_in_view(&mut self, doc: &Document) {