When the right and left arrow keys are pressed, my HTML element currently only highlights the next letter when the shift key is also pressed. How can I modify it to highlight all the letters in the word when the shift key and the right or left arrow keys are pressed simultaneously? Thank you.
Here is my current code snippet:
angular.module('myApp', [])
.controller("Ctrl_List", ["$scope", function(scope) {
scope.keyPress = function(){
var code = event.which;
if (code == 37) {
document.activeElement.selectionEnd--;
var test = false;
if(test == false){
// document.activeElement.selectionStart--;
document.activeElement.selectionEnd--;
if(document.activeElement.selectionStart == 0){
test = true;
document.activeElement.selectionEnd = 0;
document.activeElement.selectionStart = 0;
}
}
if (code == 39) {
event.preventDefault();
document.activeElement.selectionStart++;
//document.activeElement.selectionEnd++;
}
}
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<div class="container" ng-controller="Ctrl_List">
<div class="row">
<textarea name="text" unselectable="on" id="text" cols="30" rows="10" ng-keydown="keyPress();"></textarea>
</div>
</div>
My attempted solution is below:
if (event.shiftKey) {
//eval("scope." + callFun + "();");
console.log('shiftKey Pressed');
if (code == 37) {
console.log('arrow Pressed');
}
if (code == 39) {
console.log('arrow Pressed');
document.activeElement.selectionStart == 0;
document.activeElement.selectionStart++;
document.activeElement.selectionEnd++;
}
}