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

Code before:
		EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
		ur->create_action(TTR("Create LightOccluder2D Sibling"), UndoRedo::MERGE_DISABLE, node);
		ur->add_do_method(this, "_add_as_sibling_or_child", node, light_occluder_2d_instance);
		ur->add_do_reference(light_occluder_2d_instance);
		ur->add_undo_method(node != get_tree()->get_edited_scene_root() ? node->get_parent() : get_tree()->get_edited_scene_root(), "remove_child", light_occluder_2d_instance);
		ur->commit_action();
	}
}

void Sprite2DEditor::_add_as_sibling_or_child(Node *p_own_node, Node *p_new_node) {
	// Can't make sibling if own node is scene root
	if (p_own_node != get_tree()->get_edited_scene_root()) {
		p_own_node->get_parent()->add_child(p_new_node, true);
		Object::cast_to<Node2D>(p_new_node)->set_transform(Object::cast_to<Node2D>(p_own_node)->get_transform());
	} else {
		p_own_node->add_child(p_new_node, true);
	}

	p_new_node->set_owner(get_tree()->get_edited_scene_root());
}

void Sprite2DEditor::_sync_sprite_resize_mode() {
	if (node == nullptr) {
		return;
	}
	node->_editor_set_dragging_to_resize_rect(resize_region_rect->is_pressed());
}

void Sprite2DEditor::_update_sprite_resize_mode_button() {
	if (node == nullptr) {
		return;
	}
	resize_region_rect->set_disabled(!node->is_region_enabled());
	resize_region_rect->set_pressed(node->_editor_is_dragging_to_resiz_rect());
}

void Sprite2DEditor::_update_sprite_resize_mode_tooltip() {
	if (node != nullptr && node->is_region_enabled()) {
		return;
	}

	resize_region_rect->set_tooltip_text("\n" + TTR("Please set 'region_rect' to 'true'."));
}

void Sprite2DEditor::_debug_uv_input(const Ref<InputEvent> &p_input) {
	if (panner->gui_input(p_input, debug_uv->get_global_rect())) {
		accept_event();
	}
}

void Sprite2DEditor::_debug_uv_draw() {

Review comment (bug):
It's single line, so early return does not help.
```suggestion
	if (node == nullptr) {
		node->_editor_set_dragging_to_resize_rect(resize_region_rect->is_pressed());
	}
```

Code after:
		EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
		ur->create_action(TTR("Create LightOccluder2D Sibling"), UndoRedo::MERGE_DISABLE, node);
		ur->add_do_method(this, "_add_as_sibling_or_child", node, light_occluder_2d_instance);
		ur->add_do_reference(light_occluder_2d_instance);
		ur->add_undo_method(node != get_tree()->get_edited_scene_root() ? node->get_parent() : get_tree()->get_edited_scene_root(), "remove_child", light_occluder_2d_instance);
		ur->commit_action();
	}
}

void Sprite2DEditor::_add_as_sibling_or_child(Node *p_own_node, Node *p_new_node) {
	// Can't make sibling if own node is scene root
	if (p_own_node != get_tree()->get_edited_scene_root()) {
		p_own_node->get_parent()->add_child(p_new_node, true);
		Object::cast_to<Node2D>(p_new_node)->set_transform(Object::cast_to<Node2D>(p_own_node)->get_transform());
	} else {
		p_own_node->add_child(p_new_node, true);
	}

	p_new_node->set_owner(get_tree()->get_edited_scene_root());
}

void Sprite2DEditor::_sync_sprite_resize_mode() {
	if (node != nullptr) {
		node->_editor_set_dragging_to_resize_rect(resize_region_rect->is_pressed());
	}
}

void Sprite2DEditor::_update_sprite_resize_mode_button() {
	if (node == nullptr) {
		return;
	}
	resize_region_rect->set_disabled(!node->is_region_enabled());
	resize_region_rect->set_pressed(node->_editor_is_dragging_to_resiz_rect());
	resize_region_rect->set_tooltip_text(node->is_region_enabled() ? "" : TTRC("Sprite's region needs to be enabled in the inspector."));
}

void Sprite2DEditor::_debug_uv_input(const Ref<InputEvent> &p_input) {
	if (panner->gui_input(p_input, debug_uv->get_global_rect())) {
		accept_event();
	}
}

void Sprite2DEditor::_debug_uv_draw() {
	debug_uv->draw_set_transform(-draw_offset * draw_zoom, 0, Vector2(draw_zoom, draw_zoom));

	Ref<Texture2D> tex = node->get_texture();
	ERR_FAIL_COND(tex.is_null());

	debug_uv->draw_texture(tex, Point2());

	Color color = Color(1.0, 0.8, 0.7);