From 9d8ad4fbd86bca86ea5c0e262f056d4c630f6a25 Mon Sep 17 00:00:00 2001
From: sam edelsten <samedelsten1@gmail.com>
Date: Thu, 10 Aug 2023 13:14:18 +0100
Subject: [PATCH] fix broken text selection on percentage sized ui nodes

---
 TODO       | 17 +++++++----------
 src/lib.rs | 10 +++-------
 2 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/TODO b/TODO
index a20607d..1d4f2d7 100644
--- a/TODO
+++ b/TODO
@@ -3,16 +3,6 @@
 
 BUGS INTRODUCED:
 
-[ ] Cannot select text on Ui bundles sized by percentage
-        Maybe intercept percentages and set as px on instantiation?
-        Replace evaluate() with custom percent to px fn?
-            Read into how evaluate() works
-
-[ ] Window resizing broken
-    Used to redraw on click, now redraws on scroll or drag?
-    Now drag doesn't work either (tested on readonly, might be that)
-    Either way redraw on resize would be nice.
-
 [ ] Not all text boxes want to be click-selectable
     Make utils.rs in examples; move click functions there.
 
@@ -23,3 +13,10 @@ BUGS SQUASHED:
 [x] Cursor on readonly
 
 [x] MultiStyle text is fully dead. Idk what I did to it :(
+
+[x] Cannot select text on Ui bundles sized by percentage
+
+[x] Window resizing broken
+    Used to redraw on click, now redraws on scroll or drag?
+    Now drag doesn't work either (tested on readonly, might be that)
+      fixed by percentage-select fix
diff --git a/src/lib.rs b/src/lib.rs
index 21b6536..80c95e6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -652,7 +652,7 @@ pub fn cosmic_edit_bevy_events(
         With<CosmicEditor>,
     >,
     readonly_query: Query<&ReadOnly>,
-    style_query: Query<&mut Style>,
+    node_query: Query<&mut Node>,
     sprite_query: Query<&mut Sprite>,
     mut font_system: ResMut<CosmicFontSystem>,
     mut is_deleting: Local<bool>,
@@ -669,12 +669,8 @@ pub fn cosmic_edit_bevy_events(
     {
         let readonly = readonly_query.get(entity).is_ok();
 
-        let (width, height, is_ui_node) = match style_query.get(entity) {
-            Ok(style) => (
-                style.width.evaluate(1.).unwrap_or(1.),
-                style.height.evaluate(1.).unwrap_or(1.),
-                true,
-            ),
+        let (width, height, is_ui_node) = match node_query.get(entity) {
+            Ok(node) => (node.size().x, node.size().y, true),
             Err(_) => {
                 let sprite = sprite_query.get(entity).unwrap();
                 let size = sprite.custom_size.unwrap();
-- 
GitLab