diff --git a/pass/Controllers/PasswordEditorTableViewController.swift b/pass/Controllers/PasswordEditorTableViewController.swift index 4083794..b320c14 100644 --- a/pass/Controllers/PasswordEditorTableViewController.swift +++ b/pass/Controllers/PasswordEditorTableViewController.swift @@ -88,6 +88,7 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl case .fillPasswordCell: fillPasswordCell = tableView.dequeueReusableCell(withIdentifier: "fillPasswordCell", for: indexPath) as? FillPasswordTableViewCell fillPasswordCell?.delegate = self + fillPasswordCell?.contentTextField.delegate = self fillPasswordCell?.setContent(content: cellData[PasswordEditorCellKey.content] as? String) if tableData[passwordSection].count == 1 { fillPasswordCell?.settingButton.isHidden = true @@ -97,10 +98,18 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl passwordLengthCell = tableView.dequeueReusableCell(withIdentifier: "passwordLengthCell", for: indexPath) as? SliderTableViewCell let lengthSetting = Globals.passwordDefaultLength[SharedDefaults[.passwordGeneratorFlavor]] ?? Globals.passwordDefaultLength["Random"] + let minimumLength = lengthSetting?.min ?? 0 + let maximumLength = lengthSetting?.max ?? 0 + var defaultLength = lengthSetting?.def ?? 0 + if let currentPasswordLength = (tableData[passwordSection][0][PasswordEditorCellKey.content] as? String)?.characters.count, + currentPasswordLength >= minimumLength, + currentPasswordLength <= maximumLength { + defaultLength = currentPasswordLength + } passwordLengthCell?.reset(title: "Length", - minimumValue: lengthSetting?.min ?? 0, - maximumValue: lengthSetting?.max ?? 0, - defaultValue: lengthSetting?.def ?? 0) + minimumValue: minimumLength, + maximumValue: maximumLength, + defaultValue: defaultLength) passwordLengthCell?.delegate = self return passwordLengthCell! case .additionsCell: @@ -234,14 +243,16 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl } } - // update the data table after editing + // update tableData so to make sure reloadData() works correctly func textFieldDidEndEditing(_ textField: UITextField) { if textField == nameCell?.contentTextField { tableData[nameSection][0][PasswordEditorCellKey.content] = nameCell?.getContent() + } else if textField == fillPasswordCell?.contentTextField { + tableData[passwordSection][0][PasswordEditorCellKey.content] = fillPasswordCell?.getContent() } } - // update the data table after editing + // update tableData so to make sure reloadData() works correctly func textViewDidEndEditing(_ textView: UITextView) { if textView == additionsCell?.contentTextView { tableData[additionsSection][0][PasswordEditorCellKey.content] = additionsCell?.getContent() diff --git a/passKit/Helpers/Utils.swift b/passKit/Helpers/Utils.swift index 785f892..9ce518e 100644 --- a/passKit/Helpers/Utils.swift +++ b/passKit/Helpers/Utils.swift @@ -111,11 +111,13 @@ public class Utils { // draw all digits in the password into red // draw all punctuation characters in the password into blue for (index, element) in plainPassword.unicodeScalars.enumerated() { + var charColor = UIColor.darkText if NSCharacterSet.decimalDigits.contains(element) { - attributedPassword.addAttribute(NSForegroundColorAttributeName, value: Globals.red, range: NSRange(location: index, length: 1)) + charColor = Globals.red } else if !NSCharacterSet.letters.contains(element) { - attributedPassword.addAttribute(NSForegroundColorAttributeName, value: Globals.blue, range: NSRange(location: index, length: 1)) + charColor = Globals.blue } + attributedPassword.addAttribute(NSForegroundColorAttributeName, value: charColor, range: NSRange(location: index, length: 1)) } return attributedPassword }