Repository: GraphiteEditor/Graphite (language: rust)

Issue:
Make Text tool use click targets based on rectangles instead of precise glyph shapes
Currently selection in the viewport with the text tool is based on a geometry intersection. Since the geometry of the text is usually very intricate, this can be annoying.

The code for selecting existing text is in the `fn interact` in `text_tool.rs`. Currently it uses `document.click(...)`. The new functionality would need to replace this with an iteration over the layers (from top to bottom), attempting to get their text node. The bounding box function from `to_path.rs` would then be applied, which would be transformed by the `transform_to_viewport` and intersected with the cursor.


Discussion / hints:

Fix patch:
diff --git a/editor/src/messages/tool/tool_messages/text_tool.rs b/editor/src/messages/tool/tool_messages/text_tool.rs
index 9d5978e8aa..311952eef1 100644
--- a/editor/src/messages/tool/tool_messages/text_tool.rs
+++ b/editor/src/messages/tool/tool_messages/text_tool.rs
@@ -310,7 +310,23 @@ impl TextToolData {
 		responses: &mut VecDeque<Message>,
 	) -> TextToolFsmState {
 		// Check if the user has selected an existing text layer
-		if let Some(clicked_text_layer_path) = document.click(input).filter(|&layer| is_layer_fed_by_node_of_name(layer, &document.network_interface, "Text")) {
+		if let Some(clicked_text_layer_path) = document
+			.metadata()
+			.all_layers()
+			.filter(|&layer| is_layer_fed_by_node_of_name(layer, &document.network_interface, "Text"))
+			.find(|&layer| {
+				let (text, font, font_size, line_height_ratio, character_spacing) =
+					graph_modification_utils::get_text(layer, &document.network_interface).expect("Text layer should have text when interacting with the Text tool in `interact()`");
+
+				let buzz_face = font_cache.get(font).map(|data| load_face(data));
+				let far = graphene_core::text::bounding_box(text, buzz_face, font_size, line_height_ratio, character_spacing, None);
+				let quad = Quad::from_box([DVec2::ZERO, far]);
+				let transformed_quad = document.metadata().transform_to_viewport(layer) * quad;
+
+				let mouse = DVec2::new(input.mouse.position.x, input.mouse.position.y);
+
+				transformed_quad.contains(mouse)
+			}) {
 			self.start_editing_layer(clicked_text_layer_path, state, document, font_cache, responses);
 
 			TextToolFsmState::Editing


Test patch: