fix: undo and redo both work
This commit is contained in:
parent
e2926f7c3f
commit
07db1670c7
|
|
@ -1,5 +1,4 @@
|
|||
#include "edit_history.h"
|
||||
#include "macros.h"
|
||||
|
||||
EditHistory *EditHistory::singleton_instance{ nullptr };
|
||||
|
||||
|
|
@ -19,15 +18,15 @@ void EditHistory::push_action(Callable do_action, Callable undo_action) {
|
|||
}
|
||||
|
||||
void EditHistory::undo() {
|
||||
if (this->undo_count + 1 < this->history.size()) {
|
||||
if (this->undo_count < this->history.size()) {
|
||||
this->undo_count++;
|
||||
this->history[this->history.size() - this->undo_count].undo_action.call();
|
||||
}
|
||||
}
|
||||
|
||||
void EditHistory::redo() {
|
||||
if (this->undo_count > 1) {
|
||||
this->undo_count--;
|
||||
if (this->undo_count > 0) {
|
||||
this->history[this->history.size() - this->undo_count].do_action.call();
|
||||
this->undo_count--;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,25 +110,40 @@ void TerrainMeshEditor::_notification(int what) {
|
|||
|
||||
void TerrainMeshEditor::unhandled_input(Ref<InputEvent> const &event) {
|
||||
Ref<InputEventKey> key{ event };
|
||||
if (key.is_valid() && key->get_key_label() == Key::S && key->get_modifiers_mask() == (KeyModifierMask::SHIFT | KeyModifierMask::CTRL)) {
|
||||
if (!key.is_valid() || !key->is_pressed()) {
|
||||
return;
|
||||
}
|
||||
switch (key->get_key_label()) {
|
||||
default:
|
||||
return;
|
||||
case Key::S:
|
||||
if (key->is_shift_pressed() && key->is_command_or_control_pressed()) {
|
||||
get_viewport()->set_input_as_handled();
|
||||
this->file_dialog->set_file_mode(FileDialog::FILE_MODE_SAVE_FILE);
|
||||
this->file_dialog->set_ok_button_text("Save");
|
||||
this->file_dialog->popup_file_dialog();
|
||||
} else if (key.is_valid() && key->get_key_label() == Key::S && key->get_modifiers_mask() == KeyModifierMask::CTRL) {
|
||||
} else if (key->is_command_or_control_pressed()) {
|
||||
get_viewport()->set_input_as_handled();
|
||||
save_data();
|
||||
} else if (key.is_valid() && key->get_key_label() == Key::O && key->get_modifiers_mask() == KeyModifierMask::CTRL) {
|
||||
}
|
||||
break;
|
||||
case Key::O:
|
||||
if (key->is_command_or_control_pressed()) {
|
||||
get_viewport()->set_input_as_handled();
|
||||
this->file_dialog->set_file_mode(FileDialog::FILE_MODE_OPEN_FILE);
|
||||
this->file_dialog->set_ok_button_text("Open");
|
||||
this->file_dialog->popup_file_dialog();
|
||||
} else if (key.is_valid() && key->get_key_label() == Key::Z && key->get_modifiers_mask() == KeyModifierMask::CTRL) {
|
||||
get_viewport()->set_input_as_handled();
|
||||
EditHistory::get_singleton()->undo();
|
||||
} else if (key.is_valid() && key->get_key_label() == Key::Z && key->get_modifiers_mask() == (KeyModifierMask::CTRL | KeyModifierMask::SHIFT)) {
|
||||
}
|
||||
break;
|
||||
case Key::Z:
|
||||
if (key->is_shift_pressed() && key->is_command_or_control_pressed()) {
|
||||
get_viewport()->set_input_as_handled();
|
||||
EditHistory::get_singleton()->redo();
|
||||
} else if (key->is_command_or_control_pressed()) {
|
||||
get_viewport()->set_input_as_handled();
|
||||
EditHistory::get_singleton()->undo();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue