This repository was archived by the owner on Sep 8, 2020. It is now read-only.
File tree 2 files changed +36
-8
lines changed 2 files changed +36
-8
lines changed Original file line number Diff line number Diff line change @@ -218,14 +218,14 @@ angular.module('ui.ace', [])
218
218
onChange : function ( callback ) {
219
219
return function ( e ) {
220
220
var newValue = session . getValue ( ) ;
221
- if ( newValue !== scope . $eval ( attrs . value ) && ! scope . $$phase && ! scope . $root . $$phase ) {
222
- if ( ngModel !== null ) {
223
- scope . $apply ( function ( ) {
224
- ngModel . $setViewValue ( newValue ) ;
225
- } ) ;
226
- }
227
- executeUserCallback ( callback , e , acee ) ;
221
+
222
+ if ( ngModel && newValue !== ngModel . $viewValue ) {
223
+ scope . $applyAsync ( function ( ) {
224
+ ngModel . $setViewValue ( newValue ) ;
225
+ } ) ;
228
226
}
227
+
228
+ executeUserCallback ( callback , e , acee ) ;
229
229
} ;
230
230
} ,
231
231
/**
@@ -249,7 +249,7 @@ angular.module('ui.ace', [])
249
249
} ) ;
250
250
251
251
// Value Blind
252
- if ( ngModel !== null ) {
252
+ if ( ngModel ) {
253
253
ngModel . $formatters . push ( function ( value ) {
254
254
if ( angular . isUndefined ( value ) || value === null ) {
255
255
return '' ;
Original file line number Diff line number Diff line change @@ -216,8 +216,36 @@ describe('uiAce', function () {
216
216
217
217
var value = 'baz' ;
218
218
_ace . getSession ( ) . setValue ( value ) ;
219
+ scope . $apply ( ) ;
220
+
219
221
expect ( scope . foo ) . toBe ( value ) ;
220
222
} ) ;
223
+
224
+ it ( 'should update the IDE only if different' , function ( ) {
225
+ scope . change = jasmine . createSpy ( 'scope.change' ) ;
226
+
227
+ $compile ( '<div ui-ace ng-model="foo" ng-change="change(foo)">' ) ( scope ) ;
228
+
229
+ // change shouldn't be called initialy
230
+ expect ( scope . change ) . not . toHaveBeenCalled ( ) ;
231
+
232
+ // change shouldn't be called when the value change is coming from the model.
233
+ scope . $apply ( 'foo = "bar"' ) ;
234
+ expect ( scope . change ) . not . toHaveBeenCalled ( ) ;
235
+
236
+ _ace . getSession ( ) . setValue ( 'baz' ) ;
237
+ scope . $apply ( ) ;
238
+
239
+ // ace removeText event + ace insertText event
240
+ expect ( scope . change . calls . count ( ) ) . toBe ( 2 ) ;
241
+ // ace removeText event
242
+ expect ( scope . change ) . toHaveBeenCalledWith ( '' ) ;
243
+ // ace insertText event
244
+ expect ( scope . change ) . toHaveBeenCalledWith ( 'baz' ) ;
245
+
246
+ //
247
+ expect ( scope . foo ) . toBe ( 'baz' ) ;
248
+ } ) ;
221
249
} ) ;
222
250
223
251
describe ( 'when the model is undefined/null' , function ( ) {
You can’t perform that action at this time.
0 commit comments