2021-03-23 11:47:21 +01:00
|
|
|
//
|
|
|
|
// DeleteBackwardResponseTextField.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-23.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
public protocol DeleteBackwardResponseTextFieldDelegate: AnyObject {
|
2021-03-23 11:47:21 +01:00
|
|
|
func deleteBackwardResponseTextField(_ textField: DeleteBackwardResponseTextField, textBeforeDelete: String?)
|
|
|
|
}
|
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
public final class DeleteBackwardResponseTextField: UITextField {
|
2021-03-23 11:47:21 +01:00
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
public weak var deleteBackwardDelegate: DeleteBackwardResponseTextFieldDelegate?
|
2021-03-23 11:47:21 +01:00
|
|
|
|
2022-10-21 13:12:44 +02:00
|
|
|
public var textInset: UIEdgeInsets = .zero
|
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
public override func deleteBackward() {
|
2021-03-23 11:47:21 +01:00
|
|
|
let text = self.text
|
|
|
|
super.deleteBackward()
|
|
|
|
deleteBackwardDelegate?.deleteBackwardResponseTextField(self, textBeforeDelete: text)
|
|
|
|
}
|
|
|
|
|
2022-10-21 13:12:44 +02:00
|
|
|
public override func textRect(forBounds bounds: CGRect) -> CGRect {
|
|
|
|
return bounds.inset(by: textInset)
|
|
|
|
}
|
|
|
|
|
|
|
|
public override func editingRect(forBounds bounds: CGRect) -> CGRect {
|
|
|
|
return bounds.inset(by: textInset)
|
|
|
|
}
|
|
|
|
|
2021-03-23 11:47:21 +01:00
|
|
|
}
|