diff --git a/docs/widget/src/components/CommentForm.js b/docs/widget/src/components/CommentForm.js index 6632b69..e4bb4b9 100644 --- a/docs/widget/src/components/CommentForm.js +++ b/docs/widget/src/components/CommentForm.js @@ -106,6 +106,7 @@ export class CommentForm extends Component { rows: 4, disabled: submitting, onInput: (e) => this.handleFieldChange('content', e.target.value), + onKeydown: (e) => this.handleContentKeydown(e), }, }), ...(formErrors.content ? [this.createTextElement('span', formErrors.content, 'cwd-error-text')] : []), @@ -345,6 +346,18 @@ export class CommentForm extends Component { } } + handleContentKeydown(e) { + if ( + e.key === '/' && + !e.ctrlKey && + !e.metaKey && + !e.altKey && + !e.shiftKey + ) { + e.stopPropagation(); + } + } + updatePreviewContent(content) { const previewContent = this.elements.root.querySelector('.cwd-preview-content'); if (previewContent) { diff --git a/docs/widget/src/components/ReplyEditor.js b/docs/widget/src/components/ReplyEditor.js index 04cd595..63e1686 100644 --- a/docs/widget/src/components/ReplyEditor.js +++ b/docs/widget/src/components/ReplyEditor.js @@ -75,6 +75,7 @@ export class ReplyEditor extends Component { placeholder: '支持 Markdown 格式', disabled: this.props.submitting, onInput: (e) => this.handleInput(e), + onKeydown: (e) => this.handleTextareaKeydown(e), }, }), @@ -186,6 +187,18 @@ export class ReplyEditor extends Component { } } + handleTextareaKeydown(e) { + if ( + e.key === '/' && + !e.ctrlKey && + !e.metaKey && + !e.altKey && + !e.shiftKey + ) { + e.stopPropagation(); + } + } + togglePreview() { this.state.showPreview = !this.state.showPreview; this.render();