Created
January 13, 2016 18:23
-
-
Save lovasoa/e7ac08aa4f0d07ab5933 to your computer and use it in GitHub Desktop.
Forbid "incoherent" selection in a document (selection that can not be expressed as a new tag in the DOM tree)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.onmousemove = function(evt) { | |
var s = window.getSelection(); | |
if (s.rangeCount === 0) return; | |
while(s.rangeCount > 1) s.removeRange(s.getRangeAt(1)); | |
r = s.getRangeAt(0); | |
if (r.startContainer.parentNode !== r.endContainer.parentNode) { | |
r.setEnd(r.startContainer, r.startContainer.length); | |
evt.preventDefault(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment