def METHOD_NAME(self, undo_command: UndoableCommand) -> None:
    assert undo_command
    undo_command.commit()
    last_undo_command = self.__undo_stack[-1] if self.__undo_stack else None
    if last_undo_command and last_undo_command.is_mergeable and undo_command.is_mergeable and last_undo_command.command_id == undo_command.command_id:
        last_undo_command.merge(undo_command)
        undo_command.close()
    else:
        self.__undo_stack.append(undo_command)
    while len(self.__redo_stack) > 0:
        self.__redo_stack.pop().close()