ui-ace icon indicating copy to clipboard operation
ui-ace copied to clipboard

Is there a way to tell if the onchange is coming from a ng-model change or user typing?

Open Madd0g opened this issue 10 years ago • 2 comments

I'm using json editing with ace and updating an object on my scope every time the editor changes. Then I have a checkbox that a user can click to update a boolean in the object. I then reflect this in the ace editor.

Because I can't use databinding - I need to keep the values in sync manually with JSON.stringify/JSON.parse. This becomes a problem because the editor sends the onChange event even if the change comes from changing the scope value.

Is there a way of getting an event only when the ace editor changes by user input. How difficult would it be to add it? Any ideas how I can sidestep this problem?

Thanks

Madd0g avatar Jul 07 '15 11:07 Madd0g

I have a similar problem. I want to implement auto save using ace but the onChange event is called also when loading the editor with ng-model. I think that the behavior should be the same as the HTML input element where onChange is fired only if the user change the text. What do you think?

For now I have implemented auto save using onBlur.

thanks

davideicardi avatar Jul 23 '15 15:07 davideicardi

You can use

editor.getSession().on('change', function() { // do something });

Where editor is the ace instance obtained using the onLoad event in the ui-ace attribute <div ui-ace="{onLoad: onAceLoad}" ng-model="model"></div>

scope.onAceLoad = function (editor) { 
    editor.getSession().on('change', function() { // do something }); 
}

antonpodolsky avatar Sep 20 '15 15:09 antonpodolsky