From 020e9c0d31f4d037a8eb375a3a662cd469e7c107 Mon Sep 17 00:00:00 2001
From: Andy Vawer <andy@vawer.com>
Date: Sat, 4 Jul 2020 10:02:55 +0000
Subject: [PATCH] When clicking in window to move caret to another icon, remove
 any selection from other icons in the window to prevent unwanted user
 deletion of text in the selected icon.

---
 s/CnPCaret | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/s/CnPCaret b/s/CnPCaret
index dcd8340..a2994b9 100644
--- a/s/CnPCaret
+++ b/s/CnPCaret
@@ -558,7 +558,25 @@ wscp_remove_current_caret ROUT
         TST     R4,#crf_selection :OR: crf_ghostcaret
         BNE     %FT01
 
-00      ; we are dealing with the main caret, so do the check
+00      ; we are dealing with the main caret, so do the checks
+        ; is there a current selection in this window?
+        CMP     R0,#-1                ; no current window
+        LDRNE   R14,[R10,#w_seldata+wselicon]
+        CMPNE   R14,#-1               ; any current selection?
+        CMPNE   R14,R1                ; in the same icon as the new one?
+        BEQ     %FT50
+
+        ; remove current selection and redraw its icon
+        Push    "R0-R2,R10,R11"
+        MOV     R0,R14
+        MOV     R14,#-1
+        STR     R14,[R10,#w_seldata+wselicon]
+        MOV     R1,#0
+        MOV     R2,#0
+        BL      int_set_icon_state
+        Pull    "R0-R2,R10,R11"
+
+50
         LDR     R14,caretdata
         CMP     R0,R14
         BEQ     %FT01
@@ -660,7 +678,7 @@ wscp_rcc_selection_redraw
         STR     R14,redrawcareticon
         Pull    "R1-R5,R10,R11,PC"
 
-wscp_rcc_queue_redraw
+wscp_rcc_queue_redraw ROUT
         ; r11=pointer to window handle (ie caret data block or similar)
         ; r14=icon handle from the current caret state
         LDR     R11,[R11]               ; get the window handle itself
-- 
GitLab