Skip to content

Commit

Permalink
Do not use willHandleEventExclusively in editplugin (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Jul 31, 2019
1 parent 921bb34 commit 3dd68f9
Showing 1 changed file with 7 additions and 28 deletions.
35 changes: 7 additions & 28 deletions packages/roosterjs-editor-core/lib/corePlugins/EditPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
*/
export default class EditPlugin implements EditorPlugin {
private editor: Editor;
private currentFeature: GenericContentEditFeature<PluginEvent> = null;
private featureMap: { [key: number]: GenericContentEditFeature<PluginEvent>[] } = {};

private autoCompleteSnapshot: string = null;
Expand Down Expand Up @@ -45,28 +44,20 @@ export default class EditPlugin implements EditorPlugin {
*/
onPluginEvent(event: PluginEvent) {
let contentChanged = false;
let currentFeature = this.findFeature(event);

switch (event.eventType) {
case PluginEventType.ContentChanged:
if (this.autoCompleteChangeSource != event.source) {
contentChanged = true;
}
if (!this.currentFeature) {
this.findFeature(event);
}
contentChanged = this.autoCompleteChangeSource != event.source;
break;
case PluginEventType.MouseDown:
contentChanged = true;
break;
case PluginEventType.KeyDown:
contentChanged = true;
break;
}

if (this.currentFeature) {
let feature = this.currentFeature;
this.currentFeature = null;
feature.handleEvent(event, this.editor);
if (currentFeature) {
currentFeature.handleEvent(event, this.editor);
}

if (contentChanged) {
Expand All @@ -75,19 +66,6 @@ export default class EditPlugin implements EditorPlugin {
}
}

/**
* Check if the plugin should handle the given event exclusively.
* Handle an event exclusively means other plugin will not receive this event in
* onPluginEvent method.
* If two plugins will return true in willHandleEventExclusively() for the same event,
* the final result depends on the order of the plugins are added into editor
* @param event The event to check
*/
willHandleEventExclusively(event: PluginEvent) {
this.findFeature(event);
return !!this.currentFeature;
}

/**
* Add a Content Edit feature
* @param feature The feature to add
Expand Down Expand Up @@ -126,12 +104,13 @@ export default class EditPlugin implements EditorPlugin {
} else if (event.eventType == PluginEventType.ContentChanged) {
features = this.featureMap[Keys.CONTENTCHANGED];
}
this.currentFeature =
return (
features &&
features.filter(
feature =>
(feature.allowFunctionKeys || !hasFunctionKey) &&
feature.shouldHandleEvent(event, this.editor)
)[0];
)[0]
);
}
}

0 comments on commit 3dd68f9

Please sign in to comment.