diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp index 8dea764b03..5508c39dd4 100644 --- a/Userland/Applications/FontEditor/FontEditor.cpp +++ b/Userland/Applications/FontEditor/FontEditor.cpp @@ -345,8 +345,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& did_modify_font(); }; - m_glyph_editor_widget->on_undo_event = [this](bool) { - // FIXME: UndoStack no longer has finalization concept, so this needs some fixing. + m_glyph_editor_widget->on_undo_event = [this] { m_undo_stack->push(make(*m_undo_glyph)); did_change_undo_stack(); }; diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp index 7419cad052..31ae531354 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp @@ -38,13 +38,11 @@ void GlyphEditorWidget::set_glyph(int glyph) void GlyphEditorWidget::delete_glyph() { if (on_undo_event) - on_undo_event(false); + on_undo_event(); auto bitmap = font().glyph(m_glyph).glyph_bitmap(); for (int x = 0; x < bitmap.width(); x++) for (int y = 0; y < bitmap.height(); y++) bitmap.set_bit_at(x, y, false); - if (on_undo_event) - on_undo_event(true); if (on_glyph_altered) on_glyph_altered(m_glyph); update(); @@ -93,7 +91,7 @@ void GlyphEditorWidget::paste_glyph() return; if (on_undo_event) - on_undo_event(false); + on_undo_event(); auto byte_buffer = GUI::Clipboard::the().data(); auto buffer_height = GUI::Clipboard::the().data_and_type().metadata.get("height").value().to_int(); @@ -115,8 +113,7 @@ void GlyphEditorWidget::paste_glyph() bitmap.set_bit_at(x, y, bits[x][y]); } } - if (on_undo_event) - on_undo_event(true); + if (on_glyph_altered) on_glyph_altered(m_glyph); update(); @@ -175,7 +172,7 @@ void GlyphEditorWidget::mousedown_event(GUI::MouseEvent& event) return; m_is_clicking_valid_cell = true; if (on_undo_event) - on_undo_event(false); + on_undo_event(); if (mode() == Paint) { draw_at_mouse(event); } else { @@ -195,8 +192,6 @@ void GlyphEditorWidget::mouseup_event(GUI::MouseEvent&) if (!m_is_clicking_valid_cell) return; m_is_clicking_valid_cell = false; - if (on_undo_event) - on_undo_event(true); } void GlyphEditorWidget::mousemove_event(GUI::MouseEvent& event) diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.h b/Userland/Applications/FontEditor/GlyphEditorWidget.h index b98e77aefd..9a5d6cf7f9 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.h +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.h @@ -47,7 +47,7 @@ public: void set_mode(Mode mode) { m_mode = mode; } Function on_glyph_altered; - Function on_undo_event; + Function on_undo_event; private: GlyphEditorWidget() {}; diff --git a/Userland/Applications/FontEditor/UndoGlyph.h b/Userland/Applications/FontEditor/UndoGlyph.h index b1324c1743..63e571248c 100644 --- a/Userland/Applications/FontEditor/UndoGlyph.h +++ b/Userland/Applications/FontEditor/UndoGlyph.h @@ -46,20 +46,23 @@ private: class GlyphUndoCommand : public GUI::Command { public: GlyphUndoCommand(UndoGlyph& glyph) - : m_state(glyph.save_state()) + : m_undo_state(glyph.save_state()) , m_undo_glyph(glyph) { } virtual void undo() override { - m_undo_glyph.restore_state(*m_state); + if (!m_redo_state) + m_redo_state = m_undo_state->save_state(); + m_undo_glyph.restore_state(*m_undo_state); } virtual void redo() override { - undo(); + m_undo_glyph.restore_state(*m_redo_state); } private: - RefPtr m_state; + RefPtr m_undo_state; + RefPtr m_redo_state; UndoGlyph& m_undo_glyph; };