summaryrefslogtreecommitdiff
path: root/helix-view/src/editor.rs
diff options
context:
space:
mode:
authorMichael Davis2023-06-26 15:17:04 +0000
committerGitHub2023-06-26 15:17:04 +0000
commit636c91c76b2855a4ac58b3a030a9e45f88eb7502 (patch)
tree3db92e67f8adb059a501520680f43c021fb1d501 /helix-view/src/editor.rs
parent8d39a81aa88a813c6a3e1734e5cb3c05fd723839 (diff)
Mark buffers created from stdin as modified (#7431)
This resolves some confusing behavior where a scratch document created by piping into hx is discarded when navigating away from that document. We discard any scratch documents that are not modified and the original `Editor::new_file_from_stdin` would create unmodified documents. We refactor this function to create an empty document first and then to apply the text from stdin as a change.
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r--helix-view/src/editor.rs21
1 files changed, 16 insertions, 5 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 1a884c32..61d148d3 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -1386,11 +1386,22 @@ impl Editor {
}
pub fn new_file_from_stdin(&mut self, action: Action) -> Result<DocumentId, Error> {
- let (rope, encoding, has_bom) = crate::document::from_reader(&mut stdin(), None)?;
- Ok(self.new_file_from_document(
- action,
- Document::from(rope, Some((encoding, has_bom)), self.config.clone()),
- ))
+ let (stdin, encoding, has_bom) = crate::document::read_to_string(&mut stdin(), None)?;
+ let doc = Document::from(
+ helix_core::Rope::default(),
+ Some((encoding, has_bom)),
+ self.config.clone(),
+ );
+ let doc_id = self.new_file_from_document(action, doc);
+ let doc = doc_mut!(self, &doc_id);
+ let view = view_mut!(self);
+ doc.ensure_view_init(view.id);
+ let transaction =
+ helix_core::Transaction::insert(doc.text(), doc.selection(view.id), stdin.into())
+ .with_selection(Selection::point(0));
+ doc.apply(&transaction, view.id);
+ doc.append_changes_to_history(view);
+ Ok(doc_id)
}
// ??? possible use for integration tests