commit 6a8083c7e92a23fac5c0bd4e7b73723d6e2c88b8
parent 367246067ae003855bfcf39dc01b51dcab77f11e
Author: Hunter
Date: Tue, 30 Jul 2024 22:59:59 -0400
cmd+c to copy highligted task text or substring
Diffstat:
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/todo.html b/todo.html
@@ -107,6 +107,7 @@
taskInput.addEventListener('keydown', backspaceHandler.keydown);
taskInput.addEventListener('keyup', backspaceHandler.keyup);
+ taskInput.addEventListener('keydown', copyActiveTaskText);
taskInput.addEventListener('input', () => {
task.text = taskInput.value;
@@ -465,6 +466,22 @@
}
}
+ function copyActiveTaskText(e) {
+ // Check if the key combination is Ctrl+C (Windows) or Cmd+C (Mac)
+ if ((e.ctrlKey || e.metaKey) && e.key === 'c') {
+ const activeTaskInput = document.querySelector('.task-container.active input[type="text"]');
+ if (activeTaskInput) {
+ // Check if there's a selection within the active task input
+ const selectedText = activeTaskInput.value.substring(activeTaskInput.selectionStart, activeTaskInput.selectionEnd);
+
+ const textToCopy = selectedText || activeTaskInput.value;
+
+ e.preventDefault(); // Prevent default copy behavior
+ navigator.clipboard.writeText(textToCopy);
+ }
+ }
+ }
+
renderCurrentView();
});
</script>