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

Code before:

		if (bool(EDITOR_DEF("editors/animation/confirm_insert_track", true))) {
			//potential new key, does not exist
			if (num_tracks == 1) {
				// TRANSLATORS: %s will be replaced by a phrase describing the target of track.
				insert_confirm_text->set_text(vformat(TTR("Create new track for %s and insert key?"), p_id.query));
			} else {
				insert_confirm_text->set_text(vformat(TTR("Create %d new tracks and insert keys?"), num_tracks));
			}

			insert_confirm_bezier->set_visible(all_bezier);
			insert_confirm_reset->set_visible(reset_allowed);

			insert_confirm->get_ok_button()->set_text(TTR("Create"));
			insert_confirm->popup_centered();
			insert_query = true;
		} else {
			call_deferred(SNAME("_insert_delay"), reset_allowed && EDITOR_GET("editors/animation/default_create_reset_tracks"), all_bezier && EDITOR_GET("editors/animation/default_create_bezier_tracks"));
			insert_queue = true;
		}

	} else {
		if (!insert_query && !insert_queue) {
			// Create Beziers wouldn't make sense in this case, where no tracks are being created
			call_deferred(SNAME("_insert_delay"), reset_allowed && EDITOR_GET("editors/animation/default_create_reset_tracks"), false);
			insert_queue = true;
		}
	}
}

void AnimationTrackEditor::_insert_delay(bool p_create_reset, bool p_create_beziers) {
	if (insert_query) {
		//discard since it's entered into query mode
		insert_queue = false;
		return;
	}

	undo_redo->create_action(TTR("Anim Insert"));

	Ref<Animation> reset_anim;
	if (p_create_reset) {
		reset_anim = _create_and_get_reset_animation();
	}

	TrackIndices next_tracks(animation.ptr(), reset_anim.ptr());
	bool advance = false;
	while (insert_data.size()) {
		if (insert_data.front()->get().advance) {
			advance = true;
		}
		next_tracks = _confirm_insert(insert_data.front()->get(), next_tracks, p_create_reset, reset_anim, p_create_beziers);

Review comment (suggestion):
While at it, could improve the comment style:
```suggestion
		// Prevent insertion of multiple tracks.
		if (E.path == p_id.path) {
			return; // Already inserted a track for this on this frame.
```

Code after:
}

void AnimationTrackEditor::_query_insert(const InsertData &p_id) {
	if (!insert_queue) {
		insert_data.clear();
	}

	for (const InsertData &E : insert_data) {
		// Prevent insertion of multiple tracks.
		if (E.path == p_id.path) {
			return; // Already inserted a track this frame.
		}
	}

	insert_data.push_back(p_id);

	// Without queue, commit immediately.
	if (!insert_queue) {
		commit_insert_queue();
	}
}

void AnimationTrackEditor::_insert_track(bool p_create_reset, bool p_create_beziers) {
	undo_redo->create_action(TTR("Anim Insert"));

	Ref<Animation> reset_anim;
	if (p_create_reset) {
		reset_anim = _create_and_get_reset_animation();
	}

	TrackIndices next_tracks(animation.ptr(), reset_anim.ptr());
	bool advance = false;
	while (insert_data.size()) {
		if (insert_data.front()->get().advance) {
			advance = true;
		}
		next_tracks = _confirm_insert(insert_data.front()->get(), next_tracks, p_create_reset, reset_anim, p_create_beziers);
		insert_data.pop_front();
	}

	undo_redo->commit_action();

	if (advance) {
		float step = animation->get_step();
		if (step == 0) {
			step = 1;
		}

		float pos = timeline->get_play_position();

		pos = Math::snapped(pos + step, step);