CKEditor是否提供有关鼠标与键盘触发“更改”事件的属性? [英] Does CKEditor provide a property for when the 'change' event was triggered by mouse vs keyboard?

查看:230
本文介绍了CKEditor是否提供有关鼠标与键盘触发“更改”事件的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当鼠标和键盘触发更改事件时,CKEditor是否提供属性?

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.

推荐答案

否,没有此类信息。 editor#change 事件只是CKEditor撤消管理器的副作用,在某些情况下,甚至什么都没有改变,它甚至可能会被触发(文档中提到了这一点)。听起来很奇怪,但有充分的理由说明它如此工作。

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.

更改的来源很多-鼠标,键盘,粘贴(粘贴内容的方法有很多) ,剪切,工具栏中的按钮, editor.setData 调用以及外部代码通过命令进行的整个更改范围,也可以直接在编辑器的editable元素中进行。换句话说-无法听所有这一切,因为没有事件代表所有这些入口点。

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".

所以您可以认为编辑器的撤消管理器可以最少听键盘事件或拖放事件并记录这些更改(加上带有该信息的 change 事件)。不。例如,剪贴板插件监听本地粘贴事件,并将其转换为更有用的编辑器事件。这些事件具有侦听器,这些侦听器随后将内容插入编辑器或将其删除(以防剪切)。如果撤消管理器直接侦听粘贴操作,而使用编辑器事件取消了某些粘贴操作,则撤消管理器会感到困惑。取而代之的是,撤消管理器希望它会收到有关可能的更改的通知。这是通过 editor#saveSnapshot 事件。当某些代码知道更改了内容时,应触发这些事件(更改前后)。

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.

这篇关于CKEditor是否提供有关鼠标与键盘触发“更改”事件的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆