Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/cloud/lib/editor/components/CodeMirrorEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef } from 'react'
import React, { useCallback, useEffect, useRef } from 'react'
import CodeMirror from '../../editor/CodeMirror'
import { CodeMirrorBinding } from 'y-codemirror'
import { useEffectOnce } from 'react-use'
Expand Down Expand Up @@ -29,6 +29,20 @@ const CodeMirrorEditor = ({
const onScrollLineRef = useRef(onLineScroll)
const skipOnScrollRef = useRef(false)

const applySpellcheckToInput = useCallback((enabled: boolean) => {
if (editorRef.current == null) {
return
}

const inputField = (editorRef.current as any).getInputField?.()

if (inputField != null) {
inputField.setAttribute('spellcheck', enabled ? 'true' : 'false')
inputField.setAttribute('autocorrect', enabled ? 'on' : 'off')
inputField.setAttribute('autocapitalize', enabled ? 'sentences' : 'off')
}
}, [])

useEffect(() => {
onScrollLineRef.current = onLineScroll
}, [onLineScroll])
Expand Down Expand Up @@ -65,6 +79,8 @@ const CodeMirrorEditor = ({
{ leading: true, trailing: true }
)
)

applySpellcheckToInput(Boolean(config.spellcheck))
}
})

Expand All @@ -82,8 +98,10 @@ const CodeMirrorEditor = ({
val
)
})

applySpellcheckToInput(Boolean(config.spellcheck))
}
}, [config])
}, [config, applySpellcheckToInput])

useEffect(() => {
if (realtime == null || editorRef.current == null) {
Expand Down