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

@@ -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) => {
const removeBtn = e.target.closest('.editor-tag-remove');
if (removeBtn) {
@@ -496,16 +509,18 @@ document.addEventListener('DOMContentLoaded', () => {
});
document.getElementById('editor-contributor-input').addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
const val = e.target.value.trim();
if (val && !editorContributors.includes(val)) {
editorContributors.push(val);
renderContributorTags();
updatePreview();
}
e.target.value = '';
if (e.isComposing) {
return;
}
if (e.key === 'Enter' || e.key === ' ' || e.code === 'Space') {
e.preventDefault();
commitContributorInput();
}
});
document.getElementById('editor-contributor-input').addEventListener('blur', () => {
commitContributorInput();
});
// Click on wrapper focuses input