Skip to content

Commit 9a3667e

Browse files
committed
preserve chat spellcheck in settings
1 parent d43d455 commit 9a3667e

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/defaultOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const defaultOptions = {
6969
chatVanillaRestrictions: true,
7070
debugResponseTimeIndicator: false,
7171
chatPingExtension: true,
72+
chatSpellCheckEnabled: false,
7273
// antiAliasing: false,
7374
topRightTimeDisplay: 'only-fullscreen' as 'only-fullscreen' | 'always' | 'never',
7475

src/react/Chat.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ type Props = {
8383
debugChatScroll?: boolean
8484
getPingComplete?: (value: string) => Promise<string[]>
8585
currentPlayerName?: string
86+
spellCheckEnabled?: boolean
87+
onSpellCheckEnabledChange?: (enabled: boolean) => void
8688
}
8789

8890
export const chatInputValueGlobal = proxy({
@@ -103,7 +105,9 @@ export default ({
103105
chatVanillaRestrictions,
104106
debugChatScroll,
105107
getPingComplete,
106-
currentPlayerName
108+
currentPlayerName,
109+
spellCheckEnabled = false,
110+
onSpellCheckEnabledChange
107111
}: Props) => {
108112
const playerNameValidated = useMemo(() => {
109113
if (!/^[\w\d_]+$/i.test(currentPlayerName ?? '')) return ''
@@ -112,7 +116,6 @@ export default ({
112116

113117
const sendHistoryRef = useRef(JSON.parse(window.sessionStorage.chatHistory || '[]'))
114118
const [isInputFocused, setIsInputFocused] = useState(false)
115-
const [spellCheckEnabled, setSpellCheckEnabled] = useState(false)
116119
const [preservedInputValue, setPreservedInputValue] = useState('')
117120
const [inputKey, setInputKey] = useState(0)
118121
const pingHistoryRef = useRef(JSON.parse(window.localStorage.pingHistory || '[]'))
@@ -458,7 +461,7 @@ export default ({
458461
icon={pixelartIcons['text-wrap']}
459462
onClick={() => {
460463
setPreservedInputValue(chatInput.current?.value || '')
461-
setSpellCheckEnabled(!spellCheckEnabled)
464+
onSpellCheckEnabledChange?.(!spellCheckEnabled)
462465
remountInput()
463466
}}
464467
/>

src/react/ChatProvider.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ export default () => {
1818
const lastMessageId = useRef(0)
1919
const lastPingTime = useRef(0)
2020
const usingTouch = useSnapshot(miscUiState).currentTouch
21-
const { chatSelect, messagesLimit, chatOpacity, chatOpacityOpened, chatVanillaRestrictions, debugChatScroll, chatPingExtension } = useSnapshot(options)
21+
const {
22+
chatSelect,
23+
messagesLimit,
24+
chatOpacity,
25+
chatOpacityOpened,
26+
chatVanillaRestrictions,
27+
debugChatScroll,
28+
chatPingExtension,
29+
chatSpellCheckEnabled
30+
} = useSnapshot(options)
2231
const isUsingMicrosoftAuth = useMemo(() => !!lastConnectOptions.value?.authenticatedAccount, [])
2332
const { forwardChat } = useSnapshot(viewerVersionState)
2433
const { viewerConnection } = useSnapshot(gameAdditionalState)
@@ -62,6 +71,10 @@ export default () => {
6271
opened={isChatActive}
6372
placeholder={forwardChat || !viewerConnection ? undefined : 'Chat forwarding is not enabled in the plugin settings'}
6473
currentPlayerName={chatPingExtension ? bot.username : undefined}
74+
spellCheckEnabled={chatSpellCheckEnabled}
75+
onSpellCheckEnabledChange={(enabled) => {
76+
options.chatSpellCheckEnabled = enabled
77+
}}
6578
getPingComplete={async (value) => {
6679
const players = Object.keys(bot.players)
6780
return players.filter(name => (!value || name.toLowerCase().includes(value.toLowerCase())) && name !== bot.username).map(name => `@${name}`)

0 commit comments

Comments
 (0)