-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle key down events in content model only if was not handled by EditFeature #1972
Conversation
@@ -599,6 +600,9 @@ const MergeListOnBackspaceAfterList: BuildInEditFeature<PluginKeyboardEvent> = { | |||
return false; | |||
}, | |||
handleEvent: (event, editor) => { | |||
if (event.eventType == PluginEventType.KeyDown) { | |||
event.handledByEditFeature = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of setting this flag here, you can set it in EditPlugin, when an edit feature is found and used, set this flag so the flag is common for all features.
@@ -91,7 +91,9 @@ export default class ContentModelEditPlugin implements EditorPlugin { | |||
break; | |||
|
|||
case PluginEventType.KeyDown: | |||
this.handleKeyDownEvent(this.editor, event.rawEvent); | |||
if (!event.handledByEditFeature) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this down to line 120 to merge with other checks
this.handleKeyDownEvent(this.editor, event.rawEvent); | ||
this.handleKeyDownEvent( | ||
this.editor, | ||
event.rawEvent, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's pass the whole event object in, so no need to pass in two parameter separately.
editor: IContentModelEditor, | ||
rawEvent: KeyboardEvent, | ||
handledByEditFeature: boolean | ||
) { | ||
const which = rawEvent.which; | ||
|
||
if (!this.editWithContentModel || rawEvent.defaultPrevented) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add the check to handledByEditFeature. We can treat handledByEditFeature in the same way with rawEvent.defaultPrevented
To avoid conflicts between EditPlugin and ContentModelEditPlugin, the
handleByEditFeature
parameter was creates in PluginKeyDownEvent data. Therefore, if the event was already handle by a content edit feature, we sethandleByEditFeature
totrue
, thenContentModelEditPlugin
know that it the event should not be handled again.