Does CKEditor provide a property for when the 'change' event was triggered by mouse vs keyboard?

对着背影说爱祢 提交于 2019-12-11 07:16:29

问题


Does CKEditor provide a property for when the 'change' event was triggered by mouse vs keyboard?

While inside of a 'change' event invocation, I need to see how the event was triggered. In my case I have a script that changes the content area and need to take action on that but not when the keyboard causes the change.


回答1:


No, there's no such information. The editor#change event is only a side effect of CKEditor's undo manager and in some cases it may even be fired when nothing has changed (the docs mention this). That sounds odd but there are good reasons why it works this way.

There are many source of changes - mouse, keyboard, pasting (there are many ways to paste content), cutting, buttons in the toolbar, editor.setData calls and the whole spectrum of changes made by external code via commands, but also directly in the editor's editable element. In other words - it is impossible to listen to all this because there are no events representing all these "entry points".

So you could think that editor's undo manager can at least listen to keyboard events or drag and drop events and record these changes (plus fire the change event with that information). Nope. For instance, the clipboard plugin listens to the native paste events and transforms them into more useful editor events. These events have listeners which then insert content into the editor, or remove it (in case of cutting). If undo manager listened to paste directly and something cancelled paste using editor events, then the undo manger would get confused. Instead, the undo manager expects that it will be notified about possible changes. This happens through the editor#saveSnapshot event. When some piece of code knows that it changes the content, it should fire these events (before and after the change).

That's why the information about the source of the change is lost. There's a long chain of events between. Plus, in many cases it is unclear what's the source.



来源:https://stackoverflow.com/questions/28729510/does-ckeditor-provide-a-property-for-when-the-change-event-was-triggered-by-mo

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