view: document.rs cleanup

This commit is contained in:
Blaž Hrastnik 2021-03-29 15:22:43 +09:00
parent a323155b99
commit c1f2a14453
2 changed files with 14 additions and 10 deletions

View File

@ -1,4 +1,4 @@
use anyhow::Error;
use anyhow::{Context, Error};
use std::future::Future;
use std::path::{Path, PathBuf};
use std::sync::Arc;
@ -90,7 +90,8 @@ pub fn load(path: PathBuf, scopes: &[String]) -> Result<Self, Error> {
use std::{env, fs::File, io::BufReader};
let _current_dir = env::current_dir()?;
let doc = Rope::from_reader(BufReader::new(File::open(path.clone())?))?;
let file = File::open(path.clone()).context(format!("unable to open {:?}", path))?;
let doc = Rope::from_reader(BufReader::new(file))?;
// TODO: create if not found
@ -183,7 +184,7 @@ fn _apply(&mut self, transaction: &Transaction) -> bool {
let success = transaction.apply(&mut self.state);
if !transaction.changes().is_empty() {
// TODO: self.version += 1;?
self.version += 1;
// update tree-sitter syntax tree
if let Some(syntax) = &mut self.syntax {
@ -193,7 +194,11 @@ fn _apply(&mut self, transaction: &Transaction) -> bool {
.unwrap();
}
// TODO: map state.diagnostics over changes::map_pos too
// if let Some(diagnostics) = &mut self.diagnostics {
// for diagnostic in diagnostics {
// // TODO: map state.diagnostics over changes::map_pos too
// }
// }
// emit lsp notification
if let Some(language_server) = &self.language_server {
@ -230,7 +235,6 @@ pub fn apply(&mut self, transaction: &Transaction) -> bool {
pub fn undo(&mut self) -> bool {
if let Some(transaction) = self.history.undo() {
self.version += 1;
let success = self._apply(&transaction);
// reset changeset to fix len
@ -243,8 +247,6 @@ pub fn undo(&mut self) -> bool {
pub fn redo(&mut self) -> bool {
if let Some(transaction) = self.history.redo() {
self.version += 1;
let success = self._apply(&transaction);
// reset changeset to fix len
@ -266,9 +268,6 @@ pub fn append_changes_to_history(&mut self) {
// annotations either add a new layer or compose into the previous one.
let transaction = Transaction::from(changes).with_selection(self.selection().clone());
// increment document version
self.version += 1;
// HAXX: we need to reconstruct the state as it was before the changes..
let old_state = self.old_state.take().expect("no old_state available");

View File

@ -174,6 +174,11 @@ pub fn documents(&self) -> impl Iterator<Item = &Document> {
self.documents.iter().map(|(_id, doc)| doc)
}
// pub fn current_document(&self) -> Document {
// let id = self.view().doc;
// let doc = &mut editor.documents[id];
// }
pub fn cursor_position(&self) -> Option<helix_core::Position> {
const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
let view = self.view();