diff --git a/.changeset/restore-ios-chat-spellcheck.md b/.changeset/restore-ios-chat-spellcheck.md new file mode 100644 index 0000000..f1650f4 --- /dev/null +++ b/.changeset/restore-ios-chat-spellcheck.md @@ -0,0 +1,5 @@ +--- +"@jmfederico/pi-web": patch +--- + +Restore spellcheck and autocorrect for prose in the web chat prompt while keeping command-like input protected from autocorrection. diff --git a/src/client/src/components/PromptEditor.ts b/src/client/src/components/PromptEditor.ts index 4eff972..78f2581 100644 --- a/src/client/src/components/PromptEditor.ts +++ b/src/client/src/components/PromptEditor.ts @@ -109,6 +109,7 @@ export class PromptEditor extends LitElement { indentUnit.of(" "), syntaxHighlighting(defaultHighlightStyle, { fallback: true }), EditorView.lineWrapping, + EditorView.contentAttributes.of((view) => inputAssistanceContentAttributes(view.state.sliceDoc(0, view.state.selection.main.head))), placeholder("Message pi... Use / for commands, @ for files"), this.editableCompartment.of(EditorView.editable.of(!this.disabled)), this.readOnlyCompartment.of(EditorState.readOnly.of(this.disabled)), @@ -299,3 +300,22 @@ function emptyFileSuggestions(): FileSuggestion[] { return []; } +const proseInputAssistanceAttributes: Record = { + spellcheck: "true", + autocorrect: "on", + autocapitalize: "sentences", + writingsuggestions: "true", +}; + +const codeLikeInputAssistanceAttributes: Record = { + spellcheck: "false", + autocorrect: "off", + autocapitalize: "off", + writingsuggestions: "false", +}; + +function inputAssistanceContentAttributes(draftBeforeCursor: string): Record { + // CodeMirror is optimized for code and disables these by default, but the chat prompt is usually prose. + return inputModeForDraft(draftBeforeCursor).kind === "normal" ? proseInputAssistanceAttributes : codeLikeInputAssistanceAttributes; +} +