fix(widget): 阻止评论输入框中的斜杠键事件冒泡

防止在评论和回复编辑器的文本区域中输入斜杠字符“/”时,触发全局快捷键操作。
This commit is contained in:
anghunk
2026-02-02 13:12:28 +08:00
parent e6bbac8366
commit 132f2fbbb0
2 changed files with 26 additions and 0 deletions

View File

@@ -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) {

View File

@@ -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();