fix(widget): 阻止评论输入框中的斜杠键事件冒泡
防止在评论和回复编辑器的文本区域中输入斜杠字符“/”时,触发全局快捷键操作。
This commit is contained in:
@@ -106,6 +106,7 @@ export class CommentForm extends Component {
|
|||||||
rows: 4,
|
rows: 4,
|
||||||
disabled: submitting,
|
disabled: submitting,
|
||||||
onInput: (e) => this.handleFieldChange('content', e.target.value),
|
onInput: (e) => this.handleFieldChange('content', e.target.value),
|
||||||
|
onKeydown: (e) => this.handleContentKeydown(e),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
...(formErrors.content ? [this.createTextElement('span', formErrors.content, 'cwd-error-text')] : []),
|
...(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) {
|
updatePreviewContent(content) {
|
||||||
const previewContent = this.elements.root.querySelector('.cwd-preview-content');
|
const previewContent = this.elements.root.querySelector('.cwd-preview-content');
|
||||||
if (previewContent) {
|
if (previewContent) {
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ export class ReplyEditor extends Component {
|
|||||||
placeholder: '支持 Markdown 格式',
|
placeholder: '支持 Markdown 格式',
|
||||||
disabled: this.props.submitting,
|
disabled: this.props.submitting,
|
||||||
onInput: (e) => this.handleInput(e),
|
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() {
|
togglePreview() {
|
||||||
this.state.showPreview = !this.state.showPreview;
|
this.state.showPreview = !this.state.showPreview;
|
||||||
this.render();
|
this.render();
|
||||||
|
|||||||
Reference in New Issue
Block a user