]> git.ardis.lu - event-hashes/commitdiff
Fix Chrome triple click over-selecting
authorArdis Lu <ardisglu@gmail.com>
Mon, 22 Jul 2024 03:03:25 +0000 (20:03 -0700)
committerArdis Lu <ardisglu@gmail.com>
Mon, 22 Jul 2024 03:03:25 +0000 (20:03 -0700)
Otherwise, triple click will select a trailing element which results in a trailing tab or newline when pasted.

index.html

index 5e5e07cff00a1a2b72daa706047a5d0eb802b321..f2aa44331be060e9b61f7e8f7acfb5bcc3068514 100644 (file)
         textarea.focus();
       }
     });
+
+    // Fix Chrome selecting trailing element on triple (or quad) click, resulting in a trailing tab or newline
+    // when copying text from the table.
+    addEventListener('click', e => {
+      if (e.detail >= 3 && table.contains(e.target)) {
+        const selection = getSelection();
+        const range = selection.getRangeAt(0);
+        const textNode = e.target.firstChild;
+        range.setStart(textNode, 0);
+        range.setEnd(textNode, textNode.length);
+      };
+    });
   </script>
 </body>
 
This page took 0.043639 seconds and 4 git commands to generate.