From 132f2fbbb08b1228a6f7f27049a9af98afd7f4de Mon Sep 17 00:00:00 2001 From: anghunk Date: Mon, 2 Feb 2026 13:12:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(widget):=20=E9=98=BB=E6=AD=A2=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E8=BE=93=E5=85=A5=E6=A1=86=E4=B8=AD=E7=9A=84=E6=96=9C?= =?UTF-8?q?=E6=9D=A0=E9=94=AE=E4=BA=8B=E4=BB=B6=E5=86=92=E6=B3=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 防止在评论和回复编辑器的文本区域中输入斜杠字符“/”时,触发全局快捷键操作。 --- docs/widget/src/components/CommentForm.js | 13 +++++++++++++ docs/widget/src/components/ReplyEditor.js | 13 +++++++++++++ 2 files changed, 26 insertions(+) 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();