From 252d5a795327c8fe8034a29be3023d711a4e20e3 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 17 Oct 2025 08:12:58 -0600 Subject: [PATCH] Filter out changes from saves in EditorTab::reload, fixes #431 --- src/tab.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/tab.rs b/src/tab.rs index 057941e..4e95f70 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -18,6 +18,17 @@ use std::{ 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 { Editor(EditorTab), GitDiff(GitDiffTab), @@ -142,6 +153,12 @@ impl EditorTab { Ok(file_content) => { 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 editor.start_change(); @@ -205,15 +222,7 @@ impl EditorTab { pub fn save(&mut self) { if let Some(path) = &self.path_opt { let mut editor = self.editor.lock().unwrap(); - let mut text = String::new(); - - editor.with_buffer(|buffer| { - for line in buffer.lines.iter() { - text.push_str(line.text()); - text.push_str(line.ending().as_str()); - } - }); - + let text = editor_text(&editor); match fs::write(path, &text) { Ok(()) => { editor.save_point();