mirror of https://github.com/helix-editor/helix
View::new is infallible, so is editor.switch/new_file.
parent
f2c79e245b
commit
c20813690f
|
@ -52,7 +52,7 @@ impl Application {
|
||||||
editor.open(file, Action::VerticalSplit)?;
|
editor.open(file, Action::VerticalSplit)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
editor.new_file(Action::VerticalSplit)?;
|
editor.new_file(Action::VerticalSplit);
|
||||||
}
|
}
|
||||||
|
|
||||||
compositor.push(Box::new(ui::EditorView::new()));
|
compositor.push(Box::new(ui::EditorView::new()));
|
||||||
|
|
|
@ -935,9 +935,7 @@ pub fn buffer_picker(cx: &mut Context) {
|
||||||
},
|
},
|
||||||
|editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
|
|editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
|
||||||
use helix_view::editor::Action;
|
use helix_view::editor::Action;
|
||||||
editor
|
editor.switch(*id, Action::Replace);
|
||||||
.switch(*id, Action::Replace)
|
|
||||||
.expect("editor.open failed");
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
cx.push_layer(Box::new(picker));
|
cx.push_layer(Box::new(picker));
|
||||||
|
|
|
@ -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 crate::tree::Layout;
|
||||||
use helix_core::Selection;
|
use helix_core::Selection;
|
||||||
match action {
|
match action {
|
||||||
|
@ -87,17 +87,17 @@ impl Editor {
|
||||||
let doc = &mut self.documents[id];
|
let doc = &mut self.documents[id];
|
||||||
doc.selections.insert(view_id, Selection::point(0));
|
doc.selections.insert(view_id, Selection::point(0));
|
||||||
|
|
||||||
return Ok(id);
|
return;
|
||||||
}
|
}
|
||||||
Action::HorizontalSplit => {
|
Action::HorizontalSplit => {
|
||||||
let view = View::new(id)?;
|
let view = View::new(id);
|
||||||
let view_id = self.tree.split(view, Layout::Horizontal);
|
let view_id = self.tree.split(view, Layout::Horizontal);
|
||||||
// initialize selection for view
|
// initialize selection for view
|
||||||
let doc = &mut self.documents[id];
|
let doc = &mut self.documents[id];
|
||||||
doc.selections.insert(view_id, Selection::point(0));
|
doc.selections.insert(view_id, Selection::point(0));
|
||||||
}
|
}
|
||||||
Action::VerticalSplit => {
|
Action::VerticalSplit => {
|
||||||
let view = View::new(id)?;
|
let view = View::new(id);
|
||||||
let view_id = self.tree.split(view, Layout::Vertical);
|
let view_id = self.tree.split(view, Layout::Vertical);
|
||||||
// initialize selection for view
|
// initialize selection for view
|
||||||
let doc = &mut self.documents[id];
|
let doc = &mut self.documents[id];
|
||||||
|
@ -106,16 +106,15 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
self._refresh();
|
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;
|
use helix_core::Rope;
|
||||||
let doc = Document::new(Rope::from("\n"));
|
let doc = Document::new(Rope::from("\n"));
|
||||||
let id = self.documents.insert(doc);
|
let id = self.documents.insert(doc);
|
||||||
self.documents[id].id = id;
|
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> {
|
pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> {
|
||||||
|
@ -159,7 +158,8 @@ impl Editor {
|
||||||
id
|
id
|
||||||
};
|
};
|
||||||
|
|
||||||
self.switch(id, action)
|
self.switch(id, action);
|
||||||
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close(&mut self, id: ViewId) {
|
pub fn close(&mut self, id: ViewId) {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use anyhow::Error;
|
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use crate::{Document, DocumentId, ViewId};
|
use crate::{Document, DocumentId, ViewId};
|
||||||
|
@ -63,17 +61,15 @@ pub struct View {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl View {
|
impl View {
|
||||||
pub fn new(doc: DocumentId) -> Result<Self, Error> {
|
pub fn new(doc: DocumentId) -> Self {
|
||||||
let view = Self {
|
Self {
|
||||||
id: ViewId::default(),
|
id: ViewId::default(),
|
||||||
doc,
|
doc,
|
||||||
first_line: 0,
|
first_line: 0,
|
||||||
first_col: 0,
|
first_col: 0,
|
||||||
area: Rect::default(), // will get calculated upon inserting into tree
|
area: Rect::default(), // will get calculated upon inserting into tree
|
||||||
jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel
|
jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel
|
||||||
};
|
}
|
||||||
|
|
||||||
Ok(view)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ensure_cursor_in_view(&mut self, doc: &Document) {
|
pub fn ensure_cursor_in_view(&mut self, doc: &Document) {
|
||||||
|
|
Loading…
Reference in New Issue