[WIP] ✨ feat: Lobe Editor Phase II#8
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Reviewer's GuideIntroduce a prioritized command registration API (registerHighCommand) in the editor kernel with automatic cleanup, extend types and interfaces with listener priority levels, and migrate existing keyboard commands in slash and rich keydown plugins to leverage the new API with appropriate priorities. Sequence diagram for prioritized command handling in Kernel.registerHighCommandsequenceDiagram
participant Editor
participant Kernel
participant CommandListener
Editor->>Kernel: registerHighCommand(command, listener, priority)
Kernel->>Kernel: Store listener in priority set
Editor->>Kernel: Dispatch command
Kernel->>Kernel: Iterate listeners by priority (high to low)
Kernel->>CommandListener: Invoke listener(payload, editor)
alt Listener returns true
Kernel->>Editor: Stop propagation
else Listener returns false
Kernel->>Kernel: Continue to next listener
end
Class diagram for Kernel and command registration changesclassDiagram
class Kernel {
+registerHighCommand<P>(command, listener, priority): () => void
-_commands: Commands
-_commandsClean: Map<LexicalCommand<unknown>, () => void>
}
class IEditor {
+registerHighCommand<P>(command, listener, priority): () => void
}
class IEditorKernel {
+registerHighCommand<P>(command, listener, priority): () => void
}
Kernel --|> IEditorKernel
IEditorKernel --|> IEditor
class Commands {
Map<LexicalCommand<unknown>, Array<Set<CommandListener<unknown>>>>
}
Kernel --> Commands
Kernel --> "Map<LexicalCommand<unknown>, () => void>" _commandsClean
Class diagram for CommandListenerPriority and priority constantsclassDiagram
class CommandListenerPriority {
<<type>>
0 | 1 | 2 | 3 | 4
}
class COMMAND_PRIORITY_EDITOR {
<<constant>>
= 0
}
class COMMAND_PRIORITY_LOW {
<<constant>>
= 1
}
class COMMAND_PRIORITY_NORMAL {
<<constant>>
= 2
}
class COMMAND_PRIORITY_HIGH {
<<constant>>
= 3
}
class COMMAND_PRIORITY_CRITICAL {
<<constant>>
= 4
}
CommandListenerPriority <|-- COMMAND_PRIORITY_EDITOR
CommandListenerPriority <|-- COMMAND_PRIORITY_LOW
CommandListenerPriority <|-- COMMAND_PRIORITY_NORMAL
CommandListenerPriority <|-- COMMAND_PRIORITY_HIGH
CommandListenerPriority <|-- COMMAND_PRIORITY_CRITICAL
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
👍 @canisminor1990 |
commit: |
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Consider extracting the repeated mergeRegister blocks in ReactSlashPlugin into a reusable helper to reduce boilerplate and improve readability.
- The registerHighCommand implementation always uses COMMAND_PRIORITY_CRITICAL under the hood—verify that this aligns with your intended priority handling and won’t interfere with other normal-priority listeners.
- After invoking the cleanup callback in registerHighCommand, remember to delete its entry from the _commandsClean map as well to avoid potential memory leaks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the repeated mergeRegister blocks in ReactSlashPlugin into a reusable helper to reduce boilerplate and improve readability.
- The registerHighCommand implementation always uses COMMAND_PRIORITY_CRITICAL under the hood—verify that this aligns with your intended priority handling and won’t interfere with other normal-priority listeners.
- After invoking the cleanup callback in registerHighCommand, remember to delete its entry from the _commandsClean map as well to avoid potential memory leaks.
## Individual Comments
### Comment 1
<location> `src/plugins/slash/react/ReactSlashPlugin.tsx:140` </location>
<code_context>
-export function registerRichKeydown(editor: LexicalEditor) {
+export function registerRichKeydown(editor: LexicalEditor, kernel: IEditor) {
return mergeRegister(
- editor.registerCommand(
+ kernel.registerHighCommand(
</code_context>
<issue_to_address>
All command registrations now use COMMAND_PRIORITY_CRITICAL; consider if this is necessary for every command.
Using COMMAND_PRIORITY_CRITICAL for all commands may block lower-priority listeners. Please evaluate if some commands can use a lower priority for better flexibility.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| (item): item is ISlashMenuOption => | ||
| !('type' in item && item.type === 'divider') && 'key' in item && Boolean(item.key), | ||
| ); | ||
| return mergeRegister( |
There was a problem hiding this comment.
suggestion: All command registrations now use COMMAND_PRIORITY_CRITICAL; consider if this is necessary for every command.
Using COMMAND_PRIORITY_CRITICAL for all commands may block lower-priority listeners. Please evaluate if some commands can use a lower priority for better flexibility.
… insert cursor node
|
❤️ Great PR @canisminor1990 ❤️ |
|
🎉 This PR is included in version 1.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
📝 补充信息 | Additional Information
Summary by Sourcery
Introduce a new high-priority command registration API and migrate existing Lexical command handlers to leverage prioritized dispatch in slash and rich-keydown plugins.
New Features:
Enhancements: