move cursor to start of input when task is blurred

Hunter
Sunday, August 11th, 2024 at 3:59 PM

index.html+10-4
readme.md+1-1

index.html
411  				taskInput.addEventListener('keydown', keydownHandler);
412  				taskInput.addEventListener('keyup', keyupHandler);
413  				taskInput.addEventListener('keydown', handleCopyAndCut);
414 +				taskInput.addEventListener('blur', function() {
415 +					placeCursorAtBeginning(this);
416 +				});
417  
418  				taskInput.addEventListener('input', () => {
419  					task.text = taskInput.value;

707  			}
708  
709  			function selectAndFocusTask(task) {
710 +				const activeInput = document.querySelector('.task-container.active input[type="text"]');
711 +				if (activeInput) {
712 +					placeCursorAtBeginning(activeInput);
713 +				}
714 +
715  				const taskInput = document.querySelector(`.task-container[data-id="${task.id}"] input[type="text"]`);
716  				if (taskInput) {
717  					taskInput.focus();

720  				}
721  			}
722  
    -			function placeCursorAtBeginning(taskInput) {
    -				taskInput.setSelectionRange(0, 0);
723 +			function placeCursorAtBeginning(input) {
724 +				input.setSelectionRange(0, 0);
725  			}
726  
727  			function navigateTasks(direction) {

733  				if (direction === 'up') {
734  					if (currentIndex > 0) {
735  						const prevTask = currentIndex === 1 ? currentTask : tasks[currentIndex - 2];
    -						placeCursorAtBeginning(currentElement);
736  						selectAndFocusTask(prevTask);
737  					}
738  				} else {
739  					if (currentIndex < tasks.length) {
    -						placeCursorAtBeginning(currentElement);
740  						selectAndFocusTask(tasks[currentIndex]);
741  					}
742  				}
readme.md
 5  <a href="https://hunterirving.github.io/matryoshka/"><img src="screenshot.gif" width="560px"></a><br>
 6  
 7  <b><i>try it now <a href="https://hunterirving.github.io/matryoshka/">in your browser</a> !</i></b>
   -<br>(physical keyboard required (for now))
 8 +<br>(physical keyboard required for now)
 9  
10  ### key features
11  - unlimited subtask depth