Skip to content

Commit 2293da7

Browse files
Nitish-botKeavon
andauthored
Improve Text tool click targets on text layers to use the text box (#2145)
* Fix text selection * Remove old implementation * minor change * Use inbuilt function instead of helper * Code review --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent 1639a2a commit 2293da7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

editor/src/messages/tool/tool_messages/text_tool.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,23 @@ impl TextToolData {
310310
responses: &mut VecDeque<Message>,
311311
) -> TextToolFsmState {
312312
// Check if the user has selected an existing text layer
313-
if let Some(clicked_text_layer_path) = document.click(input).filter(|&layer| is_layer_fed_by_node_of_name(layer, &document.network_interface, "Text")) {
313+
if let Some(clicked_text_layer_path) = document
314+
.metadata()
315+
.all_layers()
316+
.filter(|&layer| is_layer_fed_by_node_of_name(layer, &document.network_interface, "Text"))
317+
.find(|&layer| {
318+
let (text, font, font_size, line_height_ratio, character_spacing) =
319+
graph_modification_utils::get_text(layer, &document.network_interface).expect("Text layer should have text when interacting with the Text tool in `interact()`");
320+
321+
let buzz_face = font_cache.get(font).map(|data| load_face(data));
322+
let far = graphene_core::text::bounding_box(text, buzz_face, font_size, line_height_ratio, character_spacing, None);
323+
let quad = Quad::from_box([DVec2::ZERO, far]);
324+
let transformed_quad = document.metadata().transform_to_viewport(layer) * quad;
325+
326+
let mouse = DVec2::new(input.mouse.position.x, input.mouse.position.y);
327+
328+
transformed_quad.contains(mouse)
329+
}) {
314330
self.start_editing_layer(clicked_text_layer_path, state, document, font_cache, responses);
315331

316332
TextToolFsmState::Editing

0 commit comments

Comments
 (0)