|
492 | 492 | if (rowCol.row === $scope.row && rowCol.col === $scope.col && !$scope.col.colDef.enableCellEditOnFocus) {
|
493 | 493 | //important to do this before scrollToIfNecessary
|
494 | 494 | beginEditKeyDown(evt);
|
495 |
| - uiGridCtrl.grid.api.core.scrollToIfNecessary(rowCol.row, rowCol.col); |
| 495 | + // uiGridCtrl.grid.api.core.scrollToIfNecessary(rowCol.row, rowCol.col); |
496 | 496 | }
|
497 | 497 |
|
498 | 498 | });
|
|
582 | 582 | }
|
583 | 583 |
|
584 | 584 |
|
| 585 | + function beginEdit(triggerEvent) { |
| 586 | + //we need to scroll the cell into focus before invoking the editor |
| 587 | + $scope.grid.api.core.scrollToIfNecessary($scope.row, $scope.col) |
| 588 | + .then(function () { |
| 589 | + beginEditAfterScroll(triggerEvent); |
| 590 | + }); |
| 591 | + } |
| 592 | + |
585 | 593 | /**
|
586 | 594 | * @ngdoc property
|
587 | 595 | * @name editDropdownOptionsArray
|
|
666 | 674 | * </pre>
|
667 | 675 | *
|
668 | 676 | */
|
669 |
| - function beginEdit(triggerEvent) { |
| 677 | + function beginEditAfterScroll(triggerEvent) { |
670 | 678 | // If we are already editing, then just skip this so we don't try editing twice...
|
671 | 679 | if (inEdit) {
|
672 | 680 | return;
|
|
738 | 746 |
|
739 | 747 | //stop editing when grid is scrolled
|
740 | 748 | var deregOnGridScroll = $scope.col.grid.api.core.on.scrollBegin($scope, function () {
|
741 |
| - endEdit(true); |
| 749 | + endEdit(); |
742 | 750 | $scope.grid.api.edit.raise.afterCellEdit($scope.row.entity, $scope.col.colDef, cellModel($scope), origCellValue);
|
743 | 751 | deregOnGridScroll();
|
744 | 752 | deregOnEndCellEdit();
|
745 | 753 | deregOnCancelCellEdit();
|
746 | 754 | });
|
747 | 755 |
|
748 | 756 | //end editing
|
749 |
| - var deregOnEndCellEdit = $scope.$on(uiGridEditConstants.events.END_CELL_EDIT, function (evt, retainFocus) { |
750 |
| - endEdit(retainFocus); |
| 757 | + var deregOnEndCellEdit = $scope.$on(uiGridEditConstants.events.END_CELL_EDIT, function () { |
| 758 | + endEdit(); |
751 | 759 | $scope.grid.api.edit.raise.afterCellEdit($scope.row.entity, $scope.col.colDef, cellModel($scope), origCellValue);
|
752 | 760 | deregOnEndCellEdit();
|
753 | 761 | deregOnGridScroll();
|
|
766 | 774 | $scope.grid.api.edit.raise.beginCellEdit($scope.row.entity, $scope.col.colDef, triggerEvent);
|
767 | 775 | }
|
768 | 776 |
|
769 |
| - function endEdit(retainFocus) { |
| 777 | + function endEdit() { |
770 | 778 | $scope.grid.disableScrolling = false;
|
771 | 779 | if (!inEdit) {
|
772 | 780 | return;
|
|
779 | 787 | inEdit = false;
|
780 | 788 | registerBeginEditEvents();
|
781 | 789 | $scope.grid.api.core.notifyDataChange( uiGridConstants.dataChange.EDIT );
|
| 790 | + //sometimes the events can't keep up with the keyboard and grid focus is lost, so always focus |
| 791 | + //back to grid here |
| 792 | + if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) { |
| 793 | + uiGridCtrl.focus(); |
| 794 | + } |
782 | 795 | }
|
783 | 796 |
|
784 | 797 | function cancelEdit() {
|
|
790 | 803 | $scope.$apply();
|
791 | 804 |
|
792 | 805 | $scope.grid.api.edit.raise.cancelCellEdit($scope.row.entity, $scope.col.colDef);
|
793 |
| - endEdit(true); |
| 806 | + endEdit(); |
794 | 807 | }
|
795 | 808 |
|
796 | 809 | // resolves a string path against the given object
|
|
832 | 845 | *
|
833 | 846 | */
|
834 | 847 | module.directive('uiGridEditor',
|
835 |
| - ['gridUtil', 'uiGridConstants', 'uiGridEditConstants','$timeout', |
836 |
| - function (gridUtil, uiGridConstants, uiGridEditConstants, $timeout) { |
| 848 | + ['gridUtil', 'uiGridConstants', 'uiGridEditConstants','$timeout', 'uiGridEditService', |
| 849 | + function (gridUtil, uiGridConstants, uiGridEditConstants, $timeout, uiGridEditService) { |
837 | 850 | return {
|
838 | 851 | scope: true,
|
839 |
| - require: ['?^uiGrid', '?^uiGridRenderContainer'], |
| 852 | + require: ['?^uiGrid', '?^uiGridRenderContainer', 'ngModel'], |
840 | 853 | compile: function () {
|
841 | 854 | return {
|
842 | 855 | pre: function ($scope, $elm, $attrs) {
|
843 | 856 |
|
844 | 857 | },
|
845 | 858 | post: function ($scope, $elm, $attrs, controllers) {
|
846 |
| - var uiGridCtrl, renderContainerCtrl; |
| 859 | + var uiGridCtrl, renderContainerCtrl, ngModel; |
847 | 860 | if (controllers[0]) { uiGridCtrl = controllers[0]; }
|
848 | 861 | if (controllers[1]) { renderContainerCtrl = controllers[1]; }
|
| 862 | + if (controllers[2]) { ngModel = controllers[2]; } |
849 | 863 |
|
850 | 864 | //set focus at start of edit
|
851 |
| - $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () { |
852 |
| - $elm[0].focus(); |
853 |
| - $elm[0].select(); |
| 865 | + $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function (evt,triggerEvent) { |
| 866 | + $timeout(function () { |
| 867 | + $elm[0].focus(); |
| 868 | + $elm[0].select(); |
| 869 | + }); |
| 870 | + |
| 871 | + //set the keystroke that started the edit event |
| 872 | + //we must do this because the BeginEdit is done in a different event loop than the intitial |
| 873 | + //keydown event |
| 874 | + //fire this event for the keypress that is received |
| 875 | + if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) { |
| 876 | + var viewPortKeyDownUnregister = uiGridCtrl.grid.api.cellNav.on.viewPortKeyPress($scope, function (evt, rowCol) { |
| 877 | + if (uiGridEditService.isStartEditKey(evt)) { |
| 878 | + ngModel.$setViewValue(String.fromCharCode(evt.keyCode), evt); |
| 879 | + ngModel.$render(); |
| 880 | + } |
| 881 | + viewPortKeyDownUnregister(); |
| 882 | + }); |
| 883 | + } |
854 | 884 |
|
855 | 885 | $elm.on('blur', function (evt) {
|
856 | 886 | $scope.stopEdit(evt);
|
|
0 commit comments