Repository: godotengine/godot
File: core/object/undo_redo.cpp (C++)

Code before:
	}

	action_level++;

	force_keep_in_merge_ends = false;
}

void UndoRedo::add_do_method(const Callable &p_callable) {
	ERR_FAIL_COND(p_callable.is_null());
	ERR_FAIL_COND(action_level <= 0);
	ERR_FAIL_COND((current_action + 1) >= actions.size());

	Object *object = p_callable.get_object();
	ERR_FAIL_NULL(object);

	Operation do_op;
	do_op.callable = p_callable;
	do_op.object = p_callable.get_object_id();
	if (Object::cast_to<RefCounted>(object)) {
		do_op.ref = Ref<RefCounted>(Object::cast_to<RefCounted>(object));
	}
	do_op.type = Operation::TYPE_METHOD;
	do_op.name = p_callable.get_method();

	actions.write[current_action + 1].do_ops.push_back(do_op);
}

void UndoRedo::add_undo_method(const Callable &p_callable) {
	ERR_FAIL_COND(p_callable.is_null());
	ERR_FAIL_COND(action_level <= 0);
	ERR_FAIL_COND((current_action + 1) >= actions.size());

	// No undo if the merge mode is MERGE_ENDS
	if (!force_keep_in_merge_ends && merge_mode == MERGE_ENDS) {
		return;
	}

	Object *object = p_callable.get_object();
	ERR_FAIL_NULL(object);

	Operation undo_op;
	undo_op.callable = p_callable;
	undo_op.object = p_callable.get_object_id();
	if (Object::cast_to<RefCounted>(object)) {
		undo_op.ref = Ref<RefCounted>(Object::cast_to<RefCounted>(object));
	}
	undo_op.type = Operation::TYPE_METHOD;
	undo_op.force_keep_in_merge_ends = force_keep_in_merge_ends;
	undo_op.name = p_callable.get_method();

	actions.write[current_action + 1].undo_ops.push_back(undo_op);

Review comment (suggestion):
```suggestion
		// There's no `get_method()` for custom callables, so use `operator String` instead.
```
Same below.

Code after:
	}

	action_level++;

	force_keep_in_merge_ends = false;
}

void UndoRedo::add_do_method(const Callable &p_callable) {
	ERR_FAIL_COND(p_callable.is_null());
	ERR_FAIL_COND(action_level <= 0);
	ERR_FAIL_COND((current_action + 1) >= actions.size());

	ObjectID object_id = p_callable.get_object_id();
	Object *object = ObjectDB::get_instance(object_id);
	ERR_FAIL_COND(object_id.is_valid() && object == nullptr);

	Operation do_op;
	do_op.callable = p_callable;
	do_op.object = object_id;
	if (Object::cast_to<RefCounted>(object)) {
		do_op.ref = Ref<RefCounted>(Object::cast_to<RefCounted>(object));
	}
	do_op.type = Operation::TYPE_METHOD;
	do_op.name = p_callable.get_method();
	if (do_op.name == StringName()) {
		// There's no `get_method()` for custom callables, so use `operator String()` instead.
		do_op.name = static_cast<String>(p_callable);
	}

	actions.write[current_action + 1].do_ops.push_back(do_op);
}

void UndoRedo::add_undo_method(const Callable &p_callable) {
	ERR_FAIL_COND(p_callable.is_null());
	ERR_FAIL_COND(action_level <= 0);
	ERR_FAIL_COND((current_action + 1) >= actions.size());

	// No undo if the merge mode is MERGE_ENDS
	if (!force_keep_in_merge_ends && merge_mode == MERGE_ENDS) {
		return;
	}

	ObjectID object_id = p_callable.get_object_id();
	Object *object = ObjectDB::get_instance(object_id);
	ERR_FAIL_COND(object_id.is_valid() && object == nullptr);

	Operation undo_op;
	undo_op.callable = p_callable;
	undo_op.object = object_id;
	if (Object::cast_to<RefCounted>(object)) {
		undo_op.ref = Ref<RefCounted>(Object::cast_to<RefCounted>(object));