-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UITextViewDelegate-like functionality? #13
Comments
Adding my own conforming type seems to work. extension TextEditor: TextEditorViewEditingContentDelegate {
func textEditorView(_ textEditorView: TextEditorView,
updateEditingContent editingContent: TextEditorViewEditingContent)
-> TextEditorViewEditingContent? {
guard editingContent.text.count > maximumCharacterCount else { return editingContent }
let text = String(editingContent.text.prefix(maximumCharacterCount))
return EditedContent(text: text,
selectedRange: NSRange(location: text.utf16.count, length: 0))
}
}
private struct EditedContent: TextEditorViewEditingContent {
var text: String
var selectedRange: NSRange
} |
Hi, @jshier! These APIs design is actually intentional. It’s not documented by Apple, however, Also Therefore, Twitter Text Editor’s And you’re true, we have to add own By the way, for limiting number of characters, I recommend to not actually limit number of characters by the text editor level, but provides commit action to users such as adding Save or Send button to the interface then decide if application accepts the text or not when these buttons are tapped. |
Thanks, good to know I'm on the right track. I certainly understand the difficulties with
That's what I argued for but the requirements went the other way. 😢 |
Question
UITextViewDelegate
allows you to control whether the user's edits take effect throughtextView(_:shouldChangeTextIn:replacementText:)
. I can find no replacement forTwitterTextEditor
. The closest I can find isTextEditorViewEditingContentDelegate
'stextEditorView(_:updateEditingContent)
method, but returningnil
from that method doesn't seem to have the affect I want (not applying the change). It seems like I should be able to create my own editing content, but there are no types which publicly conform toTextEditorViewEditingContent
. Am I supposed to create my own conforming type? In any case, it seems like this functionality should be simpler.The text was updated successfully, but these errors were encountered: