From 65d281066d910a72a12407f089d6d09c1aa83422 Mon Sep 17 00:00:00 2001 From: mudasir-murtaza Date: Thu, 17 Oct 2024 11:22:26 +0500 Subject: [PATCH] Added keyboard shortcuts for adding tasks and submitting edits (fixes issue #18) --- script.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/script.js b/script.js index 55ea114..123569f 100644 --- a/script.js +++ b/script.js @@ -332,6 +332,20 @@ document.addEventListener('DOMContentLoaded', () => { const inputNameElement = document.querySelector('.js-name-input'); inputNameElement.focus(); + // Add event listener for "Enter" key to trigger add or edit + document.querySelector('.js-name-input').addEventListener('keydown', (e) => { + if (e.key === 'Enter') { + if (isEditing) { + // If in edit mode, call addTodo to update the task + addTodo(); + } else { + // If not in edit mode, call addTodo to add a new task + addTodo(); + } + } + }); + + // Hide edit cancel action button on page load const cancelEditBtn = document.querySelector('.js-cancel-button'); cancelEditBtn.style.display = 'none';