mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-11-29 08:29:22 +00:00
feat(ui): enable message autocorrection for normal chat input (#1870)
* feat(ui): enable autocorrection for regular chat messages while preserving it off for commands * test(ui): add unit tests for composer autocorrection policy * fix(ui): trim leading whitespace before detecting slash commands for autocorrection * fix(ui): mark shouldDisableAutocorrection internal for unit test access * fix(ui): move shouldDisableAutocorrection out of private extension
This commit is contained in:
1 parent
3b9e6ae55f
commit
bfe7bd4b58
2 files changed
+32
-1
No files matched your search
@@ -91,7 +91,12 @@ struct ContentComposerView: View {
|
||||
.bitchatFont(size: 15)
|
||||
.foregroundColor(palette.primary)
|
||||
.focused(isTextFieldFocused)
|
||||
.autocorrectionDisabled(true)
|
||||
.autocorrectionDisabled(
|
||||
Self.shouldDisableAutocorrection(
|
||||
for: messageText,
|
||||
isAutocompleting: conversationUIModel.showAutocomplete
|
||||
)
|
||||
)
|
||||
#if os(iOS)
|
||||
.textInputAutocapitalization(.sentences)
|
||||
#endif
|
||||
@@ -161,6 +166,12 @@ struct ContentComposerView: View {
|
||||
}
|
||||
}
|
||||
|
||||
extension ContentComposerView {
|
||||
static func shouldDisableAutocorrection(for text: String, isAutocompleting: Bool) -> Bool {
|
||||
isAutocompleting || text.trimmingCharacters(in: .whitespacesAndNewlines).hasPrefix("/")
|
||||
}
|
||||
}
|
||||
|
||||
private extension ContentComposerView {
|
||||
/// Static localized strings hoisted out of `body` so each keystroke in the
|
||||
/// composer doesn't perform repeated bundle lookups.
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// ContentComposerAutocorrectTests.swift
|
||||
// bitchatTests
|
||||
//
|
||||
|
||||
import Testing
|
||||
@testable import bitchat
|
||||
|
||||
struct ContentComposerAutocorrectTests {
|
||||
@Test func autocorrectionEnabledForNormalMessages() {
|
||||
#expect(!ContentComposerView.shouldDisableAutocorrection(for: "hello world", isAutocompleting: false))
|
||||
#expect(!ContentComposerView.shouldDisableAutocorrection(for: "", isAutocompleting: false))
|
||||
}
|
||||
|
||||
@Test func autocorrectionDisabledForSlashCommandsAndAutocomplete() {
|
||||
#expect(ContentComposerView.shouldDisableAutocorrection(for: "/nick alice", isAutocompleting: false))
|
||||
#expect(ContentComposerView.shouldDisableAutocorrection(for: " /nick qwerty", isAutocompleting: false))
|
||||
#expect(ContentComposerView.shouldDisableAutocorrection(for: "hey @al", isAutocompleting: true))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user