From 9e9b02a331e86c2c3f9d0fd160c42b46ad5681d2 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Mon, 16 Mar 2026 21:35:01 +0800 Subject: [PATCH] feat: enhance contributor input handling to allow space for adding names --- facilities.html | 2 +- js/facilities_script.js | 33 ++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/facilities.html b/facilities.html index 430b3da..5a22071 100644 --- a/facilities.html +++ b/facilities.html @@ -256,7 +256,7 @@
- +
diff --git a/js/facilities_script.js b/js/facilities_script.js index 531f049..64a13ab 100644 --- a/js/facilities_script.js +++ b/js/facilities_script.js @@ -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