This repository was archived by the owner on Sep 8, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +35
-6
lines changed Expand file tree Collapse file tree 2 files changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -218,13 +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 ) ) {
222
- if ( angular . isDefined ( ngModel ) ) {
221
+
222
+ if ( ngModel && newValue !== ngModel . $viewValue ) {
223
+ scope . $applyAsync ( function ( ) {
223
224
ngModel . $setViewValue ( newValue ) ;
224
- ! scope . $$phase && ! scope . $root . $$phase && scope . $digest ( ) ;
225
- }
226
- executeUserCallback ( callback , e , acee ) ;
225
+ } ) ;
227
226
}
227
+
228
+ executeUserCallback ( callback , e , acee ) ;
228
229
} ;
229
230
} ,
230
231
/**
@@ -248,7 +249,7 @@ angular.module('ui.ace', [])
248
249
} ) ;
249
250
250
251
// Value Blind
251
- if ( ngModel !== null ) {
252
+ if ( ngModel ) {
252
253
ngModel . $formatters . push ( function ( value ) {
253
254
if ( angular . isUndefined ( value ) || value === null ) {
254
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