fix: select on focus, wait for value

This commit is contained in:
Mo Bitar
2020-04-21 14:05:11 -05:00
parent 9023f76417
commit 6be8fa93f8
8 changed files with 42 additions and 36 deletions

View File

@@ -26,7 +26,7 @@ import {
fileChange,
infiniteScroll,
lowercase,
selectOnClick,
selectOnFocus,
snEnter
} from './directives/functional';
@@ -79,7 +79,7 @@ angular
.directive('fileChange', fileChange)
.directive('infiniteScroll', [infiniteScroll])
.directive('lowercase', lowercase)
.directive('selectOnClick', ['$window', selectOnClick])
.directive('selectOnFocus', ['$window', selectOnFocus])
.directive('snEnter', snEnter);
// Directives - Views

View File

@@ -5,5 +5,5 @@ export { elemReady } from './elemReady';
export { fileChange } from './file-change';
export { infiniteScroll } from './infiniteScroll';
export { lowercase } from './lowercase';
export { selectOnClick } from './selectOnClick';
export { selectOnFocus } from './selectOnFocus';
export { snEnter } from './snEnter';

View File

@@ -1,15 +0,0 @@
/* @ngInject */
export function selectOnClick($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;
/** Required for mobile Safari */
input.setSelectionRange(0, input.value.length);
}
});
}
};
}

View File

@@ -0,0 +1,17 @@
/* @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);
})
}
});
}
};
}

View File

@@ -23,8 +23,9 @@
ng-focus='self.onTitleFocus()',
ng-keyup='$event.keyCode == 13 && self.onTitleEnter($event)',
ng-model='self.editorValues.title',
select-on-click='true',
spellcheck='false')
select-on-focus='true',
spellcheck='false'
)
#save-status
.message(
ng-class="{'warning sk-bold': self.state.syncTakingTooLong, 'danger sk-bold': self.state.saveError}"

View File

@@ -17,7 +17,7 @@
ng-keyup='$event.keyCode == 13 && self.onFilterEnter();',
ng-model='self.state.noteFilter.text',
placeholder='Search',
select-on-click='true',
select-on-focus='true',
title='Searches notes in the currently selected tag'
)
#search-clear-button(

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long