From 597c5e5e13d9185d23329c020829df4b128a82a4 Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Sat, 13 Jun 2026 14:40:55 +0800
Subject: [PATCH] Fix outside blank tag removal drop

---
 src/Apptag/AppGridCollectionView.swift |   10 +++++++++-
 src/Scripts/app_ordering_data_qa.sh    |   28 ++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/src/Apptag/AppGridCollectionView.swift b/src/Apptag/AppGridCollectionView.swift
index 68e508c..5889cd3 100644
--- a/src/Apptag/AppGridCollectionView.swift
+++ b/src/Apptag/AppGridCollectionView.swift
@@ -282,10 +282,16 @@
                 if activeReorderCard === card {
                     activeReorderCard = nil
                 }
+                if lastReorderContainerID == card.containerID {
+                    lastReorderContainerID = ""
+                    lastReorderScreenFrame = nil
+                }
                 return
             }
             activeReorderCard?.clearReorderInsertion()
             activeReorderCard = nil
+            lastReorderContainerID = ""
+            lastReorderScreenFrame = nil
         }
 
         fileprivate func activeReorderPath(in containerID: String, copy: Bool) -> String? {
@@ -308,7 +314,8 @@
                   let lastReorderScreenFrame
             else { return false }
 
-            return lastReorderScreenFrame.insetBy(dx: -44, dy: -44).contains(screenPoint)
+            let guardOutset = AppGridCollectionMetrics.reorderEmptyDropCancelOutset
+            return lastReorderScreenFrame.insetBy(dx: -guardOutset, dy: -guardOutset).contains(screenPoint)
         }
 
         private static func signature(
@@ -860,6 +867,7 @@
     static let headerBottomGap: CGFloat = 6
     static let iconColumnGap: CGFloat = 6
     static let iconRowGap: CGFloat = 2
+    static let reorderEmptyDropCancelOutset: CGFloat = 4
     static let hoverScale: CGFloat = 1.22
     static let labelHeight: CGFloat = 14
 
diff --git a/src/Scripts/app_ordering_data_qa.sh b/src/Scripts/app_ordering_data_qa.sh
index 598aff4..c7e3434 100755
--- a/src/Scripts/app_ordering_data_qa.sh
+++ b/src/Scripts/app_ordering_data_qa.sh
@@ -105,6 +105,11 @@
     "AppGridGroupCardView.performDrop(path:source:sourceContainerID:copy:)",
     app_grid_text,
 )
+clear_reorder_insertion_func = extract_braced_block(
+    r"\bfileprivate\s+func\s+clearReorderInsertion\s*\(",
+    "Coordinator.clearReorderInsertion(card:)",
+    app_grid_text,
+)
 
 require(
     r"\bvar\s+containerAppOrder\s*:\s*\[String\s*:\s*\[String\]\]\s*=\s*\[:\]",
@@ -246,6 +251,29 @@
     app_grid_text,
 )
 require(
+    r"\bstatic\s+let\s+reorderEmptyDropCancelOutset\s*:\s*CGFloat\s*=\s*[0-9.]+",
+    "AppGrid must name and centralize the tiny near-edge empty-drop cancel tolerance",
+    app_grid_text,
+)
+near_edge_match = re.search(
+    r"\bstatic\s+let\s+reorderEmptyDropCancelOutset\s*:\s*CGFloat\s*=\s*([0-9.]+)",
+    app_grid_text,
+)
+if not near_edge_match or float(near_edge_match.group(1)) > 8:
+    fail("near-edge empty-drop cancel tolerance must stay below the 16px card gap so real outside blank drops remove tags")
+if re.search(r"insetBy\s*\(\s*dx\s*:\s*-44\s*,\s*dy\s*:\s*-44\s*\)", app_grid_text):
+    fail("AppGrid must not restore the old 44px empty-drop cancel zone that swallows real outside blank drops")
+require(
+    r"insetBy\s*\(\s*dx\s*:\s*-guardOutset\s*,\s*dy\s*:\s*-guardOutset\s*\)",
+    "AppGrid shouldCancelEmptyDropForActiveReorder must use the bounded near-edge tolerance",
+    app_grid_text,
+)
+require(
+    r"if\s+lastReorderContainerID\s*==\s*card\.containerID\s*\{(?:(?!\n\s*\}).)*lastReorderContainerID\s*=\s*\"\"(?:(?!\n\s*\}).)*lastReorderScreenFrame\s*=\s*nil",
+    "AppGrid must clear stale reorder frame when leaving the source card so outside blank drops can remove tags",
+    clear_reorder_insertion_func,
+)
+require(
     r"if\s+sourceContainerID\s*==\s*group\.containerID\s*\{",
     "AppGrid same-container drops, including no-op and Option drops, must be swallowed before cross-container move/copy logic",
     app_grid_perform_drop_func,

--
Gitblit v1.9.3