This repository was archived by the owner on May 25, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -61,16 +61,6 @@ angular.module('ui.codemirror', [])
61
61
if ( angular . isDefined ( scope . $eval ( iAttrs . uiCodemirror ) ) ) {
62
62
scope . $watch ( iAttrs . uiCodemirror , updateOptions , true ) ;
63
63
}
64
- // Specialize change event
65
- codeMirror . on ( 'change' , function ( instance ) {
66
- var newValue = instance . getValue ( ) ;
67
- if ( ngModel && newValue !== ngModel . $viewValue ) {
68
- ngModel . $setViewValue ( newValue ) ;
69
- }
70
- if ( ! scope . $$phase ) {
71
- scope . $apply ( ) ;
72
- }
73
- } ) ;
74
64
75
65
76
66
if ( ngModel ) {
@@ -95,6 +85,18 @@ angular.module('ui.codemirror', [])
95
85
var safeViewValue = ngModel . $viewValue || '' ;
96
86
codeMirror . setValue ( safeViewValue ) ;
97
87
} ;
88
+
89
+
90
+ // Keep the ngModel in sync with changes from CodeMirror
91
+ codeMirror . on ( 'change' , function ( instance ) {
92
+ var newValue = instance . getValue ( ) ;
93
+ if ( newValue !== ngModel . $viewValue ) {
94
+ // Changes to the model from a callback need to be wrapped in $apply or angular will not notice them
95
+ scope . $apply ( function ( ) {
96
+ ngModel . $setViewValue ( newValue ) ;
97
+ } ) ;
98
+ }
99
+ } ) ;
98
100
}
99
101
100
102
You can’t perform that action at this time.
0 commit comments