From e443a3900bc6a1f46f3906ee6147c0913c3a432e Mon Sep 17 00:00:00 2001
From: Arnold Loubriat <datatriny@gmail.com>
Date: Wed, 15 May 2024 23:03:37 +0200
Subject: [PATCH] Fix bugs with caret movement and selection changes

---
 platforms/atspi-common/src/node.rs | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/platforms/atspi-common/src/node.rs b/platforms/atspi-common/src/node.rs
index 9ec536957..9519f43f4 100644
--- a/platforms/atspi-common/src/node.rs
+++ b/platforms/atspi-common/src/node.rs
@@ -556,7 +556,13 @@ impl<'a> NodeWrapper<'a> {
         }
 
         if let Some(selection) = self.0.text_selection() {
-            if !selection.is_degenerate() {
+            if !selection.is_degenerate()
+                || old
+                    .0
+                    .text_selection()
+                    .map(|selection| !selection.is_degenerate())
+                    .unwrap_or(false)
+            {
                 adapter.emit_object_event(self.id(), ObjectEvent::TextSelectionChanged);
             }
 
@@ -1013,6 +1019,7 @@ impl PlatformNode {
                 Granularity::Word => start_offset.backward_to_word_start(),
             };
             let end = match granularity {
+                _ if start_offset.is_document_end() => return Ok((String::new(), -1, -1)),
                 Granularity::Char => start_offset.forward_to_character_end(),
                 Granularity::Line => start_offset.forward_to_line_end(),
                 Granularity::Paragraph => start_offset.forward_to_paragraph_end(),