fix(editor): enable native mobile text assistance (#6248)

This commit is contained in:
boojack 2026-08-30 11:59:16 +08:00 committed by GitHub
parent 80832c0ad1
commit 2c7cf91aac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 8 deletions

View file

@ -81,12 +81,16 @@ export function buildEditorExtensions({
markdown({ extensions: memoMarkdownExtensions }), markdown({ extensions: memoMarkdownExtensions }),
...memoEditorTheme, ...memoEditorTheme,
EditorView.lineWrapping, EditorView.lineWrapping,
// CodeMirror defaults to autocorrect="off" because it is primarily a code // CodeMirror disables native text assistance because it is primarily a code
// editor. Memos is a prose editor, and leaving that default in place also // editor. Memos is a prose editor, so restore the browser behavior used by
// routes Windows TSF input (including the Win+. emoji picker) through // the textarea editor before v0.30. Autocorrect also keeps Windows TSF input
// Chrome's autocorrect-suppression path, which has dropped committed text. // out of Chrome's autocorrect-suppression path, which has dropped committed
// Restore the browser default used by the textarea editor before v0.30. // text from the emoji picker.
EditorView.contentAttributes.of({ autocorrect: "on" }), EditorView.contentAttributes.of({
autocorrect: "on",
autocapitalize: "on",
spellcheck: "true",
}),
placeholderCompartment.of(cmPlaceholder(placeholder)), placeholderCompartment.of(cmPlaceholder(placeholder)),
EditorView.domEventHandlers({ EditorView.domEventHandlers({
paste: (event, view) => { paste: (event, view) => {

View file

@ -105,7 +105,7 @@ describe("Editor", () => {
expect(onChange).not.toHaveBeenCalledWith("server value"); expect(onChange).not.toHaveBeenCalledWith("server value");
}); });
it("keeps native autocorrection enabled for Windows text services", () => { it("enables native text assistance for prose input", () => {
const props = { const props = {
className: "x", className: "x",
initialContent: "", initialContent: "",
@ -116,7 +116,10 @@ describe("Editor", () => {
}; };
const { container } = render(<Editor {...props} />); const { container } = render(<Editor {...props} />);
expect(container.querySelector(".cm-content")).toHaveAttribute("autocorrect", "on"); const content = container.querySelector(".cm-content");
expect(content).toHaveAttribute("autocorrect", "on");
expect(content).toHaveAttribute("autocapitalize", "on");
expect(content).toHaveAttribute("spellcheck", "true");
}); });
it("reconfigures the placeholder when its translation changes", () => { it("reconfigures the placeholder when its translation changes", () => {