Skip to content

Commit

Permalink
Improve Text tool click targets on text layers to use the text box (#…
Browse files Browse the repository at this point in the history
…2145)

* Fix text selection

* Remove old implementation

* minor change

* Use inbuilt function instead of helper

* Code review

---------

Co-authored-by: Keavon Chambers <[email protected]>
  • Loading branch information
Nitish-bot and Keavon authored Dec 28, 2024
1 parent 1639a2a commit 2293da7
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion editor/src/messages/tool/tool_messages/text_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2293da7

Please sign in to comment.