Move SSD page dialog clamping to typed Kotlin

ober

300011ca5bd00e8f97f99206019a6af13d5924d1

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index 3f5d030..5b5ea66 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -3668,7 +3668,7 @@
                 selectedGroupStatus sessionCountsStatus rotatedPageStatus
                 manualGroupLabel manualCellCount editedGroupCount
                 clampPageIndex shiftPageIndex displayGroupCanvasLabel
-                dropdownHeight)
+                dropdownHeight dialogPageNumber)
         (type Int32)
         (def (normalizeFiringArc (value : String)) : String
           (string-uppercase (string-trim value)))
@@ -3825,6 +3825,18 @@
                              (pageCount : Int32)
                              (delta : Int32)) : Int32
           (clampPageIndex (+ index delta) pageCount))
+        (def (dialogPageNumber (page : (Nullable Int32))
+                               (pageCount : Int32)) : (Nullable Int32)
+          (if (nullable-null? page)
+            (nullable-none Int32)
+            (let ((value (nullable-get page))
+                  (last (if (< pageCount (int32 1)) (int32 1) pageCount)))
+              (nullable-some
+                (if (< value (int32 1))
+                  (int32 1)
+                  (if (> value last)
+                    last
+                    value))))))
         (def (appendModeStatus (group : SsdGroup)) : String
           (string-append
             "Append mode: drag boxes to add to "
@@ -5107,7 +5119,7 @@
        "            .setView(input)"
        "            .setNegativeButton(\"Cancel\", null)"
        "            .setPositiveButton(\"Load\") { _, _ ->"
-       "                val page = input.text.toString().toIntOrNull()?.coerceIn(1, pageCount) ?: return@setPositiveButton"
+       "                val page = dialogPageNumber(input.text.toString().toIntOrNull(), pageCount) ?: return@setPositiveButton"
        "                pageIndex = page - 1"
        "                renderCurrentPage()"
        "            }"