Skip to content

Commit

Permalink
Use document::from_reader to read file contents
Browse files Browse the repository at this point in the history
  • Loading branch information
idursun committed Oct 4, 2022
1 parent 05a888e commit 924907a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ops::Deref;
use std::{io::BufReader, ops::Deref};

use super::*;

Expand Down Expand Up @@ -1622,17 +1622,20 @@ fn read_file_info_buffer(
let filename = args.get(0).unwrap();
let path = PathBuf::from(filename.to_string());
if path.exists() {
match std::fs::read_to_string(path) {
Ok(contents) => {
let contents = Tendril::from(contents);
let file = std::fs::File::open(path)?;
let mut reader = BufReader::new(file);

match helix_view::document::from_reader(&mut reader, Some(doc.encoding())) {
Ok((rope, _)) => {
let rope: String = rope.into();
let contents = Tendril::from(rope);
let selection = doc.selection(view.id);
let transaction = Transaction::insert(doc.text(), selection, contents);
doc.apply(&transaction, view.id);
}
Err(error) => {
cx.editor
.set_error(format!("error reading file: {}", error));
}
Err(error) => cx
.editor
.set_error(format!("error reading file: {}", error)),
}
} else {
cx.editor
Expand Down

0 comments on commit 924907a

Please sign in to comment.