Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed undo manager to properly handle the undo stack #1504

Merged
merged 2 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ Editor::Editor() :
m_enabled(false),
m_bgr_surface(Surface::from_file("images/background/antarctic/arctis2.png")),
m_undo_manager(new UndoManager),
m_ignore_sector_change(false)
m_ignore_sector_change(false),
m_level_first_loaded(false)
{
auto toolbox_widget = std::make_unique<EditorToolboxWidget>(*this);
auto layers_widget = std::make_unique<EditorLayersWidget>(*this);
Expand Down Expand Up @@ -395,7 +396,6 @@ Editor::delete_current_sector()
void
Editor::set_level(std::unique_ptr<Level> level, bool reset)
{
m_undo_manager->reset_index();
std::string sector_name = "main";
Vector translation;

Expand Down Expand Up @@ -436,6 +436,13 @@ Editor::set_level(std::unique_ptr<Level> level, bool reset)
m_layers_widget->refresh_sector_text();
m_toolbox_widget->update_mouse_icon();
m_overlay_widget->on_level_change();

if (!m_level_first_loaded)
{
m_undo_manager->try_snapshot(*m_level);
m_undo_manager->reset_index();
m_level_first_loaded = true;
}
}

void
Expand Down
2 changes: 2 additions & 0 deletions src/editor/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class Editor final : public Screen,

std::unique_ptr<UndoManager> m_undo_manager;
bool m_ignore_sector_change;

bool m_level_first_loaded;

private:
Editor(const Editor&) = delete;
Expand Down