Filter out changes from saves in EditorTab::reload, fixes #431
This commit is contained in:
parent
913fd8b16c
commit
252d5a7953
1 changed files with 18 additions and 9 deletions
27
src/tab.rs
27
src/tab.rs
|
|
@ -18,6 +18,17 @@ use std::{
|
||||||
|
|
||||||
use crate::{Config, SYNTAX_SYSTEM, fl, git::GitDiff};
|
use crate::{Config, SYNTAX_SYSTEM, fl, git::GitDiff};
|
||||||
|
|
||||||
|
fn editor_text(editor: &ViEditor<'static, 'static>) -> String {
|
||||||
|
editor.with_buffer(|buffer| {
|
||||||
|
let mut text = String::new();
|
||||||
|
for line in buffer.lines.iter() {
|
||||||
|
text.push_str(line.text());
|
||||||
|
text.push_str(line.ending().as_str());
|
||||||
|
}
|
||||||
|
text
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub enum Tab {
|
pub enum Tab {
|
||||||
Editor(EditorTab),
|
Editor(EditorTab),
|
||||||
GitDiff(GitDiffTab),
|
GitDiff(GitDiffTab),
|
||||||
|
|
@ -142,6 +153,12 @@ impl EditorTab {
|
||||||
Ok(file_content) => {
|
Ok(file_content) => {
|
||||||
log::info!("reloaded {:?}", path);
|
log::info!("reloaded {:?}", path);
|
||||||
|
|
||||||
|
//TODO: compare using line iterator to prevent allocations
|
||||||
|
if file_content == editor_text(&editor) {
|
||||||
|
log::info!("text not changed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Store the entire operation as a single change for undo
|
// Store the entire operation as a single change for undo
|
||||||
editor.start_change();
|
editor.start_change();
|
||||||
|
|
||||||
|
|
@ -205,15 +222,7 @@ impl EditorTab {
|
||||||
pub fn save(&mut self) {
|
pub fn save(&mut self) {
|
||||||
if let Some(path) = &self.path_opt {
|
if let Some(path) = &self.path_opt {
|
||||||
let mut editor = self.editor.lock().unwrap();
|
let mut editor = self.editor.lock().unwrap();
|
||||||
let mut text = String::new();
|
let text = editor_text(&editor);
|
||||||
|
|
||||||
editor.with_buffer(|buffer| {
|
|
||||||
for line in buffer.lines.iter() {
|
|
||||||
text.push_str(line.text());
|
|
||||||
text.push_str(line.ending().as_str());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
match fs::write(path, &text) {
|
match fs::write(path, &text) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
editor.save_point();
|
editor.save_point();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue