on master help sign in
Allow switching views back to scratch buffers.
commitf2c79e245bdcc70be3c51fdca35917a929615152 authorBlaž Hrastnik <blaz@mxxn.io> dateFri 7 May 2021, 14:36 (5 years ago) parent418ee17
2 files changed+9−12
helix-term/src/commands.rs+6−9 helix-view/src/editor.rs+3−3
helix-term/src/commands.rs+6−9
@@ -930,17 +930,14 @@ pub fn buffer_picker(cx: &mut Context) {
930930 path.into()
931931 }
932932 }
933− None => "[NEW]".into(),
933+ None => "[scratch buffer]".into(),
934934 }
935935 },
936− |editor: &mut Editor, (_, path): &(DocumentId, Option<PathBuf>), _action| match path {
937− Some(path) => {
938− use helix_view::editor::Action;
939− editor
940− .open(path.into(), Action::Replace)
941− .expect("editor.open failed");
942− }
943− None => (),
936+ |editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
937+ use helix_view::editor::Action;
938+ editor
939+ .switch(*id, Action::Replace)
940+ .expect("editor.open failed");
944941 },
945942 );
946943 cx.push_layer(Box::new(picker));
helix-view/src/editor.rs+3−3
@@ -66,7 +66,7 @@ impl Editor {
6666 }
6767 }
6868
69− fn _open(&mut self, id: DocumentId, action: Action) -> Result<DocumentId, Error> {
69+ pub fn switch(&mut self, id: DocumentId, action: Action) -> Result<DocumentId, Error> {
7070 use crate::tree::Layout;
7171 use helix_core::Selection;
7272 match action {
@@ -115,7 +115,7 @@ impl Editor {
115115 let doc = Document::new(Rope::from("\n"));
116116 let id = self.documents.insert(doc);
117117 self.documents[id].id = id;
118− self._open(id, action)
118+ self.switch(id, action)
119119 }
120120
121121 pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> {
@@ -159,7 +159,7 @@ impl Editor {
159159 id
160160 };
161161
162− self._open(id, action)
162+ self.switch(id, action)
163163 }
164164
165165 pub fn close(&mut self, id: ViewId) {