Files
standardnotes-app-web/app/assets/javascripts/directives/functional/selectOnFocus.ts
2020-04-21 14:05:11 -05:00

18 lines
481 B
TypeScript

/* @ngInject */
export function selectOnFocus($window: ng.IWindowService) {
return {
restrict: 'A',
link: function (scope: ng.IScope, element: JQLite) {
element.on('focus', () => {
if (!$window.getSelection()!.toString()) {
const input = element[0] as HTMLInputElement;
/** Allow text to populate */
setImmediate(() => {
input.setSelectionRange(0, input.value.length);
})
}
});
}
};
}