cmd+c to copy highligted task text or substring

Hunter
Tuesday, July 30th, 2024 at 10:59 PM

todo.html+17 

todo.html
107  
108  				taskInput.addEventListener('keydown', backspaceHandler.keydown);
109  				taskInput.addEventListener('keyup', backspaceHandler.keyup);
110 +				taskInput.addEventListener('keydown', copyActiveTaskText);
111  
112  				taskInput.addEventListener('input', () => {
113  					task.text = taskInput.value;

466  				}
467  			}
468  
469 +			function copyActiveTaskText(e) {
470 +				// Check if the key combination is Ctrl+C (Windows) or Cmd+C (Mac)
471 +				if ((e.ctrlKey || e.metaKey) && e.key === 'c') {
472 +					const activeTaskInput = document.querySelector('.task-container.active input[type="text"]');
473 +					if (activeTaskInput) {
474 +						// Check if there's a selection within the active task input
475 +						const selectedText = activeTaskInput.value.substring(activeTaskInput.selectionStart, activeTaskInput.selectionEnd);
476 +						
477 +						const textToCopy = selectedText || activeTaskInput.value;
478 +						
479 +						e.preventDefault(); // Prevent default copy behavior
480 +						navigator.clipboard.writeText(textToCopy);
481 +					}
482 +				}
483 +			}
484 +
485  			renderCurrentView();
486  		});
487  	</script>