<commit_before>'use strict';

angular.module('mopify.widgets.directive.focusme', [
])

.directive('focusMe', function($timeout, $parse) {
    return {
        link: function(scope, element, attrs) {
            var model = $parse(attrs.focusMe);
            scope.$watch(model, function(value) {
                if(value === true) { 
                    $timeout(function() {
                        element[0].focus(); 
                    });
                }
            });
            // on blur event:
            element.bind('blur', function() {
                scope.$apply(model.assign(scope, false));
            });
        }
    };
});<commit_msg>Force cursor to be at the end after focus #105<commit_after>'use strict';

angular.module('mopify.widgets.directive.focusme', [
])

.directive('focusMe', function($timeout, $parse) {
    return {
        link: function(scope, element, attrs) {
            var model = $parse(attrs.focusMe);
            scope.$watch(model, function(value) {
                if(value === true) { 
                    $timeout(function() {
                        element[0].focus(); 

                        // Reset the value so we can be sure that the cursor is at the end of the input field
                        var value = element[0].value;
                        if(value.length > 0){
                            element[0].value = "";
                            element[0].value = value;
                        }
                    });
                }
            });
            // on blur event:
            element.bind('blur', function() {
                scope.$apply(model.assign(scope, false));
            });
        }
    };
});
{'fraction_non_alphanumeric': 0.13435474366529168, 'fraction_numerical': 0.005303476723629935, 'mean_word_length': 1.285329744279946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6632601', 'n_tokens_mistral': 444, 'n_tokens_neox': 417, 'n_words': 90}