@@ -9,6 +9,7 @@ use crate::{
9use futures_util::future;
9use futures_util::future;
11 collections::BTreeMap,
11 collections::BTreeMap,
12 path::{Path, PathBuf},
13 path::{Path, PathBuf},
14 sync::Arc,
15 sync::Arc,
@@ -314,16 +315,24 @@ impl Editor {
314 self._refresh();
315 self._refresh();
317− pub fn new_file(&mut self, action: Action) -> DocumentId {
318+ fn new_file_from_document(&mut self, action: Action, mut document: Document) -> DocumentId {
318 let id = DocumentId(self.next_document_id);
319 let id = DocumentId(self.next_document_id);
319 self.next_document_id += 1;
320 self.next_document_id += 1;
320− let mut doc = Document::default();
321− doc.id = id;
321+ document.id = id;
322− self.documents.insert(id, doc);
322+ self.documents.insert(id, document);
323 self.switch(id, action);
323 self.switch(id, action);
327+ pub fn new_file(&mut self, action: Action) -> DocumentId {
328+ self.new_file_from_document(action, Document::default())
331+ pub fn new_file_from_stdin(&mut self, action: Action) -> Result<DocumentId, Error> {
332+ let (rope, encoding) = crate::document::from_reader(&mut stdin(), None)?;
333+ Ok(self.new_file_from_document(action, Document::from(rope, Some(encoding))))
327 pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> {
336 pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> {
328 let path = helix_core::path::get_canonicalized_path(&path)?;
337 let path = helix_core::path::get_canonicalized_path(&path)?;