From 7bc674a6798aaadc4735e32c1717fa5ec5162b0f Mon Sep 17 00:00:00 2001 From: sam <43527203+bytemunch@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:29:42 +0100 Subject: [PATCH] fix first edit not being undoable (#79) Co-authored-by: StaffEngineer <111751109+StaffEngineer@users.noreply.github.com> --- src/input.rs | 2 +- src/lib.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/input.rs b/src/input.rs index 4110a3f..8881d91 100644 --- a/src/input.rs +++ b/src/input.rs @@ -450,7 +450,7 @@ pub(crate) fn input_kb( if edits.is_empty() { return; } - if edit_history.current_edit <= 1 { + if edit_history.current_edit == 0 { return; } let idx = edit_history.current_edit - 1; diff --git a/src/lib.rs b/src/lib.rs index eff2c36..d103cf7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -420,6 +420,7 @@ impl Plugin for CosmicEditPlugin { .add_systems( Update, ( + init_history, input_kb, input_mouse, blink_cursor, @@ -494,6 +495,14 @@ fn save_edit_history( }; } +fn init_history( + mut q: Query<(&mut CosmicEditor, &CosmicAttrs, &mut CosmicEditHistory), Added<CosmicEditor>>, +) { + for (mut editor, attrs, mut history) in q.iter_mut() { + save_edit_history(&mut editor.0, &attrs.0, &mut history); + } +} + /// Adds the font system to each editor when added fn cosmic_editor_builder( mut added_editors: Query<(Entity, &CosmicMetrics), Added<CosmicText>>, -- GitLab