Repository: godotengine/godot
File: editor/plugins/sprite_frames_editor_plugin.cpp (C++)

Code before:
	EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
	undo_redo->create_action(TTR("Paste Texture"), UndoRedo::MERGE_DISABLE, EditorNode::get_singleton()->get_edited_scene());

	int undo_index = frames->get_frame_count(edited_anim);

	undo_redo->add_do_method(frames.ptr(), "add_frame", edited_anim, p_texture, duration);
	undo_redo->add_undo_method(frames.ptr(), "remove_frame", edited_anim, undo_index);

	undo_redo->add_do_method(this, "_update_library");
	undo_redo->add_undo_method(this, "_update_library");
	undo_redo->commit_action();
}

void SpriteFramesEditor::_copy_pressed() {
	ERR_FAIL_COND(!frames->has_animation(edited_anim));

	Vector<int> selected_items = frame_list->get_selected_items();

	if (selected_items.is_empty()) {
		return;
	}

	Ref<ClipboardSpriteFrames> clipboard_frames = memnew(ClipboardSpriteFrames);

	for (int index = 0; index < selected_items.size(); index++) {
		int frame_index = selected_items[index];

		Ref<Texture2D> texture = frames->get_frame_texture(edited_anim, frame_index);
		if (texture.is_null()) {
			continue;
		}

		ClipboardSpriteFrames::Frame frame;
		frame.texture = texture;
		frame.duration = frames->get_frame_duration(edited_anim, frame_index);

		clipboard_frames->frames.push_back(frame);
	}
	EditorSettings::get_singleton()->set_resource_clipboard(clipboard_frames);
}

void SpriteFramesEditor::_empty_pressed() {
	ERR_FAIL_COND(!frames->has_animation(edited_anim));

	int from = -1;
	Vector<int> selected_items = frame_list->get_selected_items();

	if (!selected_items.is_empty()) {
		from = selected_items[0];
		selection.clear();
		selection.push_back(from + 1);

Review comment (suggestion):
```suggestion
	for (const int &frame_index : selected_items) {
```

Code after:
	undo_redo->create_action(TTR("Paste Texture"), UndoRedo::MERGE_DISABLE, frames.ptr());

	int undo_index = frames->get_frame_count(edited_anim);

	undo_redo->add_do_method(frames.ptr(), "add_frame", edited_anim, p_texture, duration);
	undo_redo->add_undo_method(frames.ptr(), "remove_frame", edited_anim, undo_index);

	undo_redo->add_do_method(this, "_update_library");
	undo_redo->add_undo_method(this, "_update_library");
	undo_redo->commit_action();
}

void SpriteFramesEditor::_copy_pressed() {
	ERR_FAIL_COND(!frames->has_animation(edited_anim));

	Vector<int> selected_items = frame_list->get_selected_items();

	if (selected_items.is_empty()) {
		return;
	}

	Ref<ClipboardSpriteFrames> clipboard_frames = memnew(ClipboardSpriteFrames);

	for (const int &frame_index : selected_items) {
		Ref<Texture2D> texture = frames->get_frame_texture(edited_anim, frame_index);
		if (texture.is_null()) {
			continue;
		}

		ClipboardSpriteFrames::Frame frame;
		frame.texture = texture;
		frame.duration = frames->get_frame_duration(edited_anim, frame_index);

		clipboard_frames->frames.push_back(frame);
	}
	EditorSettings::get_singleton()->set_resource_clipboard(clipboard_frames);
}

void SpriteFramesEditor::_empty_pressed() {
	ERR_FAIL_COND(!frames->has_animation(edited_anim));

	int from = -1;
	Vector<int> selected_items = frame_list->get_selected_items();

	if (!selected_items.is_empty()) {
		from = selected_items[0];
		selection.clear();
		selection.push_back(from + 1);
	} else {
		from = frames->get_frame_count(edited_anim);
	}