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

Code before:
}

List<CanvasItem *> CanvasItemEditor::_get_edited_canvas_items(bool p_retrieve_locked, bool p_remove_canvas_item_if_parent_in_selection, bool *r_has_locked_items) const {
	List<CanvasItem *> selection;
	for (const KeyValue<Node *, Object *> &E : editor_selection->get_selection()) {
		CanvasItem *ci = Object::cast_to<CanvasItem>(E.key);
		if (ci) {
			if (ci->is_visible_in_tree() && (p_retrieve_locked || !_is_node_locked(ci))) {
				Viewport *vp = ci->get_viewport();
				if (vp && !vp->is_visible_subviewport()) {
					continue;
				}
				CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(ci);
				if (se) {
					selection.push_back(ci);
				}
			} else if (r_has_locked_items) {
				// CanvasItem is selected, but can't be interacted with.
				*r_has_locked_items = true;
			}
		}
	}

	if (p_remove_canvas_item_if_parent_in_selection) {
		List<CanvasItem *> filtered_selection;
		HashSet<Node *> nodes_in_selection;
		for (CanvasItem *E : selection) {
			nodes_in_selection.insert(E);
		}
		for (CanvasItem *E : selection) {
			if (!nodes_in_selection.has(E->get_parent())) {
				filtered_selection.push_back(E);
			}
		}
		return filtered_selection;
	} else {
		return selection;
	}
}

Vector2 CanvasItemEditor::_anchor_to_position(const Control *p_control, Vector2 anchor) {
	ERR_FAIL_NULL_V(p_control, Vector2());

	Transform2D parent_transform = p_control->get_transform().affine_inverse();
	Rect2 parent_rect = p_control->get_parent_anchorable_rect();

	if (p_control->is_layout_rtl()) {
		return parent_transform.xform(parent_rect.position + Vector2(parent_rect.size.x - parent_rect.size.x * anchor.x, parent_rect.size.y * anchor.y));
	} else {
		return parent_transform.xform(parent_rect.position + Vector2(parent_rect.size.x * anchor.x, parent_rect.size.y * anchor.y));
	}

Review comment (suggestion):
```suggestion
		HashSet<const Node *> nodes_in_selection;
```

Code after:
}

List<CanvasItem *> CanvasItemEditor::_get_edited_canvas_items(bool p_retrieve_locked, bool p_remove_canvas_item_if_parent_in_selection, bool *r_has_locked_items) const {
	List<CanvasItem *> selection;
	for (const KeyValue<Node *, Object *> &E : editor_selection->get_selection()) {
		CanvasItem *ci = Object::cast_to<CanvasItem>(E.key);
		if (ci) {
			if (ci->is_visible_in_tree() && (p_retrieve_locked || !_is_node_locked(ci))) {
				Viewport *vp = ci->get_viewport();
				if (vp && !vp->is_visible_subviewport()) {
					continue;
				}
				CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(ci);
				if (se) {
					selection.push_back(ci);
				}
			} else if (r_has_locked_items) {
				// CanvasItem is selected, but can't be interacted with.
				*r_has_locked_items = true;
			}
		}
	}

	if (p_remove_canvas_item_if_parent_in_selection) {
		List<CanvasItem *> filtered_selection;
		HashSet<const Node *> nodes_in_selection;
		for (CanvasItem *E : selection) {
			nodes_in_selection.insert(E);
		}
		for (CanvasItem *E : selection) {
			if (!nodes_in_selection.has(E->get_parent())) {
				filtered_selection.push_back(E);
			}
		}
		return filtered_selection;
	} else {
		return selection;
	}
}

Vector2 CanvasItemEditor::_anchor_to_position(const Control *p_control, Vector2 anchor) {
	ERR_FAIL_NULL_V(p_control, Vector2());

	Transform2D parent_transform = p_control->get_transform().affine_inverse();
	Rect2 parent_rect = p_control->get_parent_anchorable_rect();

	if (p_control->is_layout_rtl()) {
		return parent_transform.xform(parent_rect.position + Vector2(parent_rect.size.x - parent_rect.size.x * anchor.x, parent_rect.size.y * anchor.y));
	} else {
		return parent_transform.xform(parent_rect.position + Vector2(parent_rect.size.x * anchor.x, parent_rect.size.y * anchor.y));
	}