Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Xcodes/Frontend/SignIn/PinCodeTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,34 @@ class PinCodeTextView: NSControl, NSTextFieldDelegate {

let newFieldText = field.stringValue

// Handle pasting multiple characters (e.g., pasting "123456" from clipboard)
if newFieldText.count > 1 {
// Filter to alphanumeric characters only
let validCharacters = newFieldText.filter { $0.isLetter || $0.isNumber }

// Always start from the first field and clear previous content
var newCode = Array(repeating: Character?.none, count: numberOfDigits)
for (offset, character) in validCharacters.enumerated() {
if offset < numberOfDigits {
newCode[offset] = character
}
}

// Update all fields at once to avoid triggering didSet multiple times
code = newCode

// Move focus to next empty field or the last field if all are filled
let nextEmptyIndex = code.firstIndex(where: { $0 == nil }) ?? numberOfDigits - 1
if nextEmptyIndex < characterViews.count {
window?.makeFirstResponder(characterViews[nextEmptyIndex])
} else {
resignFirstResponder()
}

return
}

// Handle single character input
let lastCharacter: Character?
if newFieldText.isEmpty {
lastCharacter = nil
Expand Down