From bfe7bd4b58f7683dfe0b4aa439d1814060d73766 Mon Sep 17 00:00:00 2001 From: Taksh Kothari Date: Sun, 29 Nov 2026 06:05:42 +0530 Subject: [PATCH] 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 --- bitchat/Views/ContentComposerView.swift | 13 +++++++++++- .../ContentComposerAutocorrectTests.swift | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 bitchatTests/ContentComposerAutocorrectTests.swift diff --git a/bitchat/Views/ContentComposerView.swift b/bitchat/Views/ContentComposerView.swift index 7290e93f..537117c3 100644 --- a/bitchat/Views/ContentComposerView.swift +++ b/bitchat/Views/ContentComposerView.swift @@ -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. diff --git a/bitchatTests/ContentComposerAutocorrectTests.swift b/bitchatTests/ContentComposerAutocorrectTests.swift new file mode 100644 index 00000000..82883c28 --- /dev/null +++ b/bitchatTests/ContentComposerAutocorrectTests.swift @@ -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)) + } +}