← All repositories

crossmate

A collaborative crossword app for iPhone and iPad

git clone https://code.inqk.net/crossmate.git


commit 2be383124f95241b33d4359f9f55c152531472fd
parent 521db69364b5beca86b6d59fccde444725f052bc
Author: Michael Camilleri <[email protected]>
Date:   Fri, 26 Jun 2026 10:34:06 +0900

Trim whitespace around rebus entries

This commit trims leading and trailing whitespace when the user commits
a rebus value that contains real content. Accidental spaces around
entries like 'PHI ' no longer become part of the shared grid state.
All-whitespace rebus values are left intact, so puzzles that
intentionally use whitespace as a cell answer can still be filled
through the rebus path.

Co-Authored-By: Codex GPT 5.5 <[email protected]>

Diffstat

MCrossmate/Models/PlayerSession.swift | 9++++++++-
MTests/Unit/PlayerSessionNavigationTests.swift | 26++++++++++++++++++++++++++

2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/Crossmate/Models/PlayerSession.swift b/Crossmate/Models/PlayerSession.swift

@@ -452,7 +452,7 @@ final class PlayerSession {
     }
 
     func commitRebus() {
-        let value = rebusBuffer
+        let value = committedRebusValue(from: rebusBuffer)
         let inputRow = selectedRow
         let inputCol = selectedCol
         isRebusActive = false
@@ -465,6 +465,13 @@ final class PlayerSession {
         }
     }
 
+    private func committedRebusValue(from buffer: String) -> String {
+        guard buffer.rangeOfCharacter(from: CharacterSet.whitespacesAndNewlines.inverted) != nil else {
+            return buffer
+        }
+        return buffer.trimmingCharacters(in: .whitespacesAndNewlines)
+    }
+
     // MARK: - Word geometry
 
     func isInCurrentWord(row: Int, col: Int) -> Bool {

diff --git a/Tests/Unit/PlayerSessionNavigationTests.swift b/Tests/Unit/PlayerSessionNavigationTests.swift

@@ -150,6 +150,32 @@ struct PlayerSessionNavigationTests {
         #expect(event.origin == .local)
     }
 
+    @Test("Rebus commit trims surrounding whitespace from non-blank entries")
+    func rebusCommitTrimsSurroundingWhitespace() throws {
+        let session = try makeNavigationSession()
+
+        session.startRebus()
+        session.rebusBuffer = " PHI "
+        session.commitRebus()
+
+        #expect(session.game.squares[0][0].entry == "PHI")
+        #expect(!session.isRebusActive)
+        #expect(session.rebusBuffer.isEmpty)
+    }
+
+    @Test("Rebus commit preserves all-whitespace entries")
+    func rebusCommitPreservesAllWhitespace() throws {
+        let session = try makeNavigationSession()
+
+        session.startRebus()
+        session.rebusBuffer = "   "
+        session.commitRebus()
+
+        #expect(session.game.squares[0][0].entry == "   ")
+        #expect(!session.isRebusActive)
+        #expect(session.rebusBuffer.isEmpty)
+    }
+
     @Test("Backspace from first down moves to final across end")
     func backspaceFromFirstDownMovesToFinalAcrossEnd() throws {
         let session = try makeNavigationSession()