问题
Is there anything like
editor.getSession.trigger('change')
the reason I want this is because the editor goes in and out of new, so when It comes back into view I need it to do its normal 'change' thing, but I dont want to wait for user input?
Currently I have
editor.getSession().on('change', function(){
editorChangeHandler()
})
and I just recall
editorChangeHandler()
when I need to, but editor.getSession.trigger('change')
is much nicer.
回答1:
editor.session._emit('change')
would trigger editorChangeHandler, but fake change event will break undo history.
回答2:
the reason I want this is because the editor goes in and out of new, so when It comes back into view I need it to do its normal 'change' thing, but I dont want to wait for user input?
You may try an alternative solution to the case using underscore.js.
Change:
editor.getSession().on('change', function(){
editorChangeHandler()
})
to:
editor.getSession().on('change', _.debounce(function() {
editorChangeHandler()
}, 100))
when you trigger a change it like:
editor.setValue('my change..');
then it will behave like your wish:
editor.getSession.trigger('change')
来源:https://stackoverflow.com/questions/16020105/ace-editor-trigger-event-using-javascript