on master help sign in
Allow switching views back to scratch buffers.
f2c79e2Blaž Hrastnik
helix-term/src/commands.rs+6−9
@@ -930,17 +930,14 @@ pub fn buffer_picker(cx: &mut Context) {
930 path.into()
930 path.into()
931 }
931 }
932 }
932 }
933− None => "[NEW]".into(),
933+ None => "[scratch buffer]".into(),
934 }
934 }
935 },
935 },
936− |editor: &mut Editor, (_, path): &(DocumentId, Option<PathBuf>), _action| match path {
936+ |editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
937− Some(path) => {
938− use helix_view::editor::Action;
937+ use helix_view::editor::Action;
939− editor
938+ editor
940− .open(path.into(), Action::Replace)
939+ .switch(*id, Action::Replace)
941− .expect("editor.open failed");
940+ .expect("editor.open failed");
942− }
943− None => (),
944 },
941 },
945 );
942 );
946 cx.push_layer(Box::new(picker));
943 cx.push_layer(Box::new(picker));
helix-view/src/editor.rs+3−3
@@ -66,7 +66,7 @@ impl Editor {
66 }
66 }
67 }
67 }
68
68
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> {
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 {
@@ -115,7 +115,7 @@ impl Editor {
115 let doc = Document::new(Rope::from("\n"));
115 let doc = Document::new(Rope::from("\n"));
116 let id = self.documents.insert(doc);
116 let id = self.documents.insert(doc);
117 self.documents[id].id = id;
117 self.documents[id].id = id;
118− self._open(id, action)
118+ self.switch(id, action)
119 }
119 }
120
120
121 pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> {
121 pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> {
@@ -159,7 +159,7 @@ impl Editor {
159 id
159 id
160 };
160 };
161
161
162− self._open(id, action)
162+ self.switch(id, action)
163 }
163 }
164
164
165 pub fn close(&mut self, id: ViewId) {
165 pub fn close(&mut self, id: ViewId) {