From 3928fef213832864fa05715a93a2a199878a52aa Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Fri, 1 May 2026 11:53:54 +0300 Subject: [PATCH] submit add child form on enter key extract the save-child handler into a submit closure shared by the save button click and a keydown listener on the input. also focus the input as soon as the form opens so the user can type and hit enter without touching the mouse. --- public/js/text.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/public/js/text.js b/public/js/text.js index 486f7f5..3b2b37e 100644 --- a/public/js/text.js +++ b/public/js/text.js @@ -117,7 +117,8 @@ function toggleAddForm(li, parentNodeId, textId) { const saveBtn = document.createElement('button'); saveBtn.textContent = 'Save'; saveBtn.className = 'save-child'; - saveBtn.addEventListener('click', () => { + + function submit() { const title = input.value.trim(); if (!title) return; @@ -133,10 +134,19 @@ function toggleAddForm(li, parentNodeId, textId) { return res.json(); }) .then(() => fetchAndRenderNodes(textId)); + } + + saveBtn.addEventListener('click', submit); + input.addEventListener('keydown', (event) => { + if (event.key === 'Enter') { + event.preventDefault(); + submit(); + } }); li.appendChild(input); li.appendChild(saveBtn); + input.focus(); } function toggleBulkAddForm(li, parentNodeId, textId) {