Filter out changes from saves in EditorTab::reload, fixes #431

This commit is contained in:
Jeremy Soller 2025-10-17 08:12:58 -06:00
parent 913fd8b16c
commit 252d5a7953
No known key found for this signature in database
GPG key ID: 670FDFB5428E05CA

View file

@ -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();