composer: spellcheck setting, off by default on touch devices
Some checks failed
CLA Assistant / CLAssistant (pull_request_target) Has been cancelled
Check PR title / lint (pull_request_target) Has been cancelled
Build pull request / Build pull request (pull_request) Has been cancelled

The composer's Editable set no spellCheck/autoCorrect/autoCapitalize/inputMode,
so the browser default (spellcheck on) applied. On Gboard that draws the red
underline and swaps the keyboard for a correction modal when the caret touches
a flagged word. Add 'Spellcheck in composer' (Settings > General > Editor),
defaulting to off when the primary pointer is coarse and on otherwise. Off also
sets autoCorrect=off, since spellCheck alone leaves the suggestion UI in place.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Void 2026-11-04 22:08:22 +00:00
commit 56f360233a
5 changed files with 59 additions and 0 deletions

View file

@ -23,6 +23,9 @@ import { RenderElement, RenderLeaf } from './Elements';
import { CustomElement } from './slate';
import * as css from './Editor.css';
import { toggleKeyboardShortcut } from './keyboard';
import { useSetting } from '../../state/hooks/settings';
import { settingsAtom } from '../../state/settings';
import { composerSpellcheckAttributes } from './spellcheck';
const initialValue: CustomElement[] = [
{
@ -90,6 +93,7 @@ export const CustomEditor = forwardRef<HTMLDivElement, CustomEditorProps>(
},
ref
) => {
const [composerSpellcheck] = useSetting(settingsAtom, 'composerSpellcheck');
const renderElement = useCallback(
(props: RenderElementProps) => <RenderElement {...props} />,
[]
@ -146,6 +150,7 @@ export const CustomEditor = forwardRef<HTMLDivElement, CustomEditorProps>(
onKeyDown={handleKeydown}
onKeyUp={onKeyUp}
onPaste={onPaste}
{...composerSpellcheckAttributes(composerSpellcheck)}
/>
</Scroll>
{after && (

View file

@ -0,0 +1,27 @@
import { describe, expect, it } from 'vitest';
import { composerSpellcheckAttributes, defaultComposerSpellcheck } from './spellcheck';
const media = (coarse: boolean) => (query: string) => ({
matches: query === '(pointer: coarse)' && coarse,
});
describe('composer spellcheck default', () => {
it('is off when the primary pointer is coarse (phone)', () => {
expect(defaultComposerSpellcheck(media(true))).toBe(false);
});
it('is on for a fine pointer (desktop)', () => {
expect(defaultComposerSpellcheck(media(false))).toBe(true);
});
it('is on when matchMedia is unavailable', () => {
expect(defaultComposerSpellcheck(undefined)).toBe(true);
});
});
describe('composer spellcheck attributes', () => {
it('off disables both spellcheck and autocorrect', () => {
expect(composerSpellcheckAttributes(false)).toEqual({ spellCheck: false, autoCorrect: 'off' });
});
it('on enables spellcheck and leaves autocorrect to the platform', () => {
expect(composerSpellcheckAttributes(true)).toEqual({ spellCheck: true });
});
});

View file

@ -0,0 +1,11 @@
/** Touch devices (phones) get the keyboard's own dictionary; desktop gets the browser's. */
export const defaultComposerSpellcheck = (
matchMedia: ((query: string) => { matches: boolean }) | undefined
): boolean => !matchMedia?.('(pointer: coarse)').matches;
/**
* Attributes for the composer's editable. Off must also switch autocorrect off:
* spellCheck alone leaves Gboard's suggestion strip and correction modal in place.
*/
export const composerSpellcheckAttributes = (enabled: boolean) =>
enabled ? ({ spellCheck: true } as const) : ({ spellCheck: false, autoCorrect: 'off' } as const);