@@ -9,6 +9,7 @@ use crate::{
99use futures_util::future;
1010use std::{
1111 collections::BTreeMap,
12+ io::stdin,
1213 path::{Path, PathBuf},
1314 pin::Pin,
1415 sync::Arc,
@@ -314,16 +315,24 @@ impl Editor {
314315 self._refresh();
315316 }
316317
317− pub fn new_file(&mut self, action: Action) -> DocumentId {
318+ fn new_file_from_document(&mut self, action: Action, mut document: Document) -> DocumentId {
318319 let id = DocumentId(self.next_document_id);
319320 self.next_document_id += 1;
320− let mut doc = Document::default();
321− doc.id = id;
322− self.documents.insert(id, doc);
321+ document.id = id;
322+ self.documents.insert(id, document);
323323 self.switch(id, action);
324324 id
325325 }
326326
327+ pub fn new_file(&mut self, action: Action) -> DocumentId {
328+ self.new_file_from_document(action, Document::default())
329+ }
330+
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))))
334+ }
335+
327336 pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> {
328337 let path = helix_core::path::get_canonicalized_path(&path)?;
329338