composer: spellcheck setting, off by default on touch devices
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:
parent
9e12f6cbe4
commit
56f360233a
5 changed files with 59 additions and 0 deletions
|
|
@ -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 && (
|
||||
|
|
|
|||
27
src/app/components/editor/spellcheck.test.ts
Normal file
27
src/app/components/editor/spellcheck.test.ts
Normal 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 });
|
||||
});
|
||||
});
|
||||
11
src/app/components/editor/spellcheck.ts
Normal file
11
src/app/components/editor/spellcheck.ts
Normal 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);
|
||||
|
|
@ -709,6 +709,10 @@ function DateAndTime() {
|
|||
|
||||
function Editor() {
|
||||
const [enterForNewline, setEnterForNewline] = useSetting(settingsAtom, 'enterForNewline');
|
||||
const [composerSpellcheck, setComposerSpellcheck] = useSetting(
|
||||
settingsAtom,
|
||||
'composerSpellcheck'
|
||||
);
|
||||
const [isMarkdown, setIsMarkdown] = useSetting(settingsAtom, 'isMarkdown');
|
||||
const [hideActivity, setHideActivity] = useSetting(settingsAtom, 'hideActivity');
|
||||
|
||||
|
|
@ -724,6 +728,15 @@ function Editor() {
|
|||
after={<Switch variant="Primary" value={enterForNewline} onChange={setEnterForNewline} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Spellcheck in composer"
|
||||
description="Underline misspelled words while typing. Off by default on touch devices, where the keyboard has its own."
|
||||
after={
|
||||
<Switch variant="Primary" value={composerSpellcheck} onChange={setComposerSpellcheck} />
|
||||
}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Markdown Formatting"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { atom } from 'jotai';
|
||||
import { defaultComposerSpellcheck } from '../components/editor/spellcheck';
|
||||
|
||||
const STORAGE_KEY = 'settings';
|
||||
export type DateFormat =
|
||||
|
|
@ -30,6 +31,7 @@ export interface Settings {
|
|||
isPeopleDrawer: boolean;
|
||||
memberSortFilterIndex: number;
|
||||
enterForNewline: boolean;
|
||||
composerSpellcheck: boolean;
|
||||
messageLayout: MessageLayout;
|
||||
messageSpacing: MessageSpacing;
|
||||
hideMembershipEvents: boolean;
|
||||
|
|
@ -64,6 +66,7 @@ const defaultSettings: Settings = {
|
|||
isPeopleDrawer: false,
|
||||
memberSortFilterIndex: 0,
|
||||
enterForNewline: false,
|
||||
composerSpellcheck: defaultComposerSpellcheck(window.matchMedia?.bind(window)),
|
||||
messageLayout: 2,
|
||||
messageSpacing: '400',
|
||||
hideMembershipEvents: false,
|
||||
|
|
|
|||
Loading…
Reference in a new issue