feat: enhance contributor input handling to allow space for adding names

This commit is contained in:
zhangyuheng
2026-03-16 21:35:01 +08:00
parent 2e0a74a3ca
commit 9e9b02a331
2 changed files with 25 additions and 10 deletions

View File

@@ -256,7 +256,7 @@
<label>贡献/维护人员</label> <label>贡献/维护人员</label>
<div class="tags-input-wrapper" id="editor-contributors-wrapper"> <div class="tags-input-wrapper" id="editor-contributors-wrapper">
<div class="tags-list" id="editor-contributors-tags"></div> <div class="tags-list" id="editor-contributors-tags"></div>
<input type="text" id="editor-contributor-input" placeholder="输入名称后按回车添加..."> <input type="text" id="editor-contributor-input" placeholder="输入名称后按回车或空格添加...">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">

View File

@@ -485,6 +485,19 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
} }
function commitContributorInput() {
const contributorInput = document.getElementById('editor-contributor-input');
const value = contributorInput.value.trim();
if (value && !editorContributors.includes(value)) {
editorContributors.push(value);
renderContributorTags();
updatePreview();
}
contributorInput.value = '';
}
document.getElementById('editor-contributors-tags').addEventListener('click', (e) => { document.getElementById('editor-contributors-tags').addEventListener('click', (e) => {
const removeBtn = e.target.closest('.editor-tag-remove'); const removeBtn = e.target.closest('.editor-tag-remove');
if (removeBtn) { if (removeBtn) {
@@ -496,18 +509,20 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
document.getElementById('editor-contributor-input').addEventListener('keydown', (e) => { document.getElementById('editor-contributor-input').addEventListener('keydown', (e) => {
if (e.key === 'Enter') { if (e.isComposing) {
return;
}
if (e.key === 'Enter' || e.key === ' ' || e.code === 'Space') {
e.preventDefault(); e.preventDefault();
const val = e.target.value.trim(); commitContributorInput();
if (val && !editorContributors.includes(val)) {
editorContributors.push(val);
renderContributorTags();
updatePreview();
}
e.target.value = '';
} }
}); });
document.getElementById('editor-contributor-input').addEventListener('blur', () => {
commitContributorInput();
});
// Click on wrapper focuses input // Click on wrapper focuses input
document.getElementById('editor-contributors-wrapper').addEventListener('click', () => { document.getElementById('editor-contributors-wrapper').addEventListener('click', () => {
document.getElementById('editor-contributor-input').focus(); document.getElementById('editor-contributor-input').focus();