Ace editor trigger event using javascript

99封情书 提交于 2019-12-10 15:48:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!