I am emulating text editor in my project with custom caret, but native selection. Is there any way how to detect in which direction did user select the text? Lets say, that
track the mousedown X offet and then the mouseup X offset, and the result shows the direction: (using jQuery)
var textSelectionDirection = (function(){
var direction = '', mouseDownOffset = null;
function getDirection(e){
if( e.type == 'mousedown' )
mouseDownOffset = e.clientX;
else if( e.type == 'mouseup' ){
direction = e.clientX < mouseDownOffset ? 'left' : 'right';
console.log(direction);
}
}
return getDirection
})();
$(document).on('mousedown mouseup', textSelectionDirection);
DEMO: http://jsfiddle.net/ffumv/