Skip to content

Deprecates EditorCommandExtension#276

Merged
Bistard merged 8 commits intodevfrom
dev-remove-command-extension
Feb 27, 2025
Merged

Deprecates EditorCommandExtension#276
Bistard merged 8 commits intodevfrom
dev-remove-command-extension

Conversation

@Bistard
Copy link
Owner

@Bistard Bistard commented Feb 27, 2025

Summary by Sourcery

Enhancements:

  • Refactor editor commands to remove the EditorCommandExtension and instead register commands directly. This change simplifies the command registration process and improves the overall architecture of the editor.

@Bistard Bistard added enhancement Improvements on existing features core refactor editor labels Feb 27, 2025
@Bistard Bistard self-assigned this Feb 27, 2025
@Bistard Bistard merged commit 9d4012e into dev Feb 27, 2025
5 checks passed
@Bistard Bistard deleted the dev-remove-command-extension branch February 27, 2025 17:39
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 27, 2025

Reviewer's Guide by Sourcery

This pull request deprecates the EditorCommandExtension and introduces a new system for registering and executing editor commands. The new system relies on the IEditorService to determine the currently focused editor and its schema, allowing commands to be executed in the correct context. The pull request also includes updates to the editor context keys, keyboard shortcut parsing, and the createRegister function.

Sequence diagram for Editor Command Execution

sequenceDiagram
    participant User
    participant EditorWidget
    participant EditorCommand
    participant IEditorService
    participant ProseMirror

    User->>EditorWidget: Executes Command
    EditorWidget->>EditorCommand: run(provider)
    activate EditorCommand
    EditorCommand->>IEditorService: getFocusedEditor()
    activate IEditorService
    IEditorService-->>EditorCommand: Returns current editor
    deactivate IEditorService
    EditorCommand->>ProseMirror: __run(provider, editor, state, dispatch, view)
    activate ProseMirror
    ProseMirror->>ProseMirror: Modifies editor state
    ProseMirror-->>EditorCommand: Returns result
    deactivate ProseMirror
    EditorCommand-->>EditorWidget: Returns result
    deactivate EditorCommand
    EditorWidget->>User: Updates UI
Loading

Updated class diagram for EditorCommand

classDiagram
  class EditorCommand {
    +run(provider: IServiceProvider): boolean | Promise<boolean>
    # __run(provider: IServiceProvider, editor: IEditorWidget, state: ProseEditorState, dispatch?: (tr: ProseTransaction) => void, view?: ProseEditorView): boolean | Promise<boolean>
  }
  class Command {
    +id: string
  }
  EditorCommand --|> Command: extends
  EditorCommand *--  IEditorWidget : uses
  EditorCommand *--  ProseEditorState : uses
  EditorCommand *--  ProseTransaction : uses
  EditorCommand *--  ProseEditorView : uses
  EditorCommand *--  IServiceProvider : uses
  note for EditorCommand "EditorCommand is executed based on the context of the current editor. If no editors is focused, will not be executed."
Loading

File-Level Changes

Change Details Files
Removes the EditorCommandExtension and its related registration logic.
  • Removes IEditorCommandExtension interface.
  • Removes registerListCommands function.
  • Removes the registration of the EditorCommandExtension in getBuiltInExtension.
  • Removes EditorCommandArguments type alias.
src/editor/contrib/command/commandList.contrib.ts
src/editor/contrib/command/command.contrib.ts
src/editor/contrib/builtInExtensionList.ts
src/editor/contrib/command/editorCommand.ts
Refactors EditorCommandBase to EditorCommand and modifies its execution logic to depend on the currently focused editor.
  • Renames EditorCommandBase to EditorCommand.
  • Introduces IEditorService to retrieve the currently focused editor.
  • The run method in EditorCommand now retrieves the current editor and its state to execute the command.
  • Introduces an abstract __run method that derived classes must implement to perform the command's logic.
  • The run method now uses the IEditorService to get the focused editor and its view to execute the command.
  • Removes EditorCommandArguments type alias.
src/editor/contrib/command/command.contrib.ts
src/editor/contrib/command/editorCommand.ts
Updates command implementations to inherit from the new EditorCommand class and use the __run method.
  • Updates Unselect, SelectAll, InsertNewLineInCodeBlock, InsertEmptyParagraphAdjacentToBlock, LiftEmptyTextBlock, SplitBlockAtSelection, DeleteSelection, JoinBackward, JoinForward, SelectNodeBackward, SelectNodeForward, ExitCodeBlock, InsertHardBreak, FileSave, FileUndo, and FileRedo to extend EditorCommand and implement __run.
  • Updates splitListItem, liftListItem, and sinkListItem to extend EditorCommand and implement __run.
src/editor/contrib/command/command.contrib.ts
src/editor/contrib/command/commandList.contrib.ts
Updates command registration to use the new EditorCommand and schema retrieval logic.
  • Introduces rendererEditorCommandRegister to register editor commands.
  • Introduces getSchemaTypeBasedOnCurrEditor to dynamically retrieve the schema based on the current editor.
  • Updates command registration to use buildEditorCommand and getSchemaTypeBasedOnCurrEditor.
  • Registers list commands, toggle mark commands, heading commands, and basic commands.
src/editor/contrib/command/command.register.ts
src/code/browser/renderer.desktop.ts
Introduces IEditorService and EditorService to manage editor focus and lifecycle.
  • Introduces IEditorService and IEditorHostService interfaces.
  • Introduces EditorService class to implement IEditorHostService.
  • Adds events for editor creation, focus, and closure.
  • Adds methods to track focused editor and retrieve all editors.
  • Registers EditorService in renderer.desktop.ts.
src/workbench/services/editor/editor.ts
src/workbench/services/editor/editorService.ts
src/code/browser/renderer.desktop.ts
src/editor/editorWidget.ts
Updates editor context keys to reflect readonly and editable states.
  • Updates isEditorReadonly and isEditorWritable context keys.
  • Introduces isEditorNotEditable context key.
src/editor/common/editorContextKeys.ts
Adds editor ID to EditorWidget and updates focus/blur events.
  • Adds a unique ID to each EditorWidget instance.
  • Updates onDidFocus and onDidBlur events to notify the IEditorService.
src/editor/editorWidget.ts
Fixes keyboard shortcut parsing.
  • Adds a check for duplicate main keys in Shortcut.fromString.
  • Adds a case for Ctrl+A in keyboard.test.ts.
src/base/common/keyboard.ts
test/base/common/keyboard.test.ts
Updates the createRegister function to pass the service provider to the register function.
  • The createRegister function now passes the service provider to the register function.
src/platform/registrant/common/registrant.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core editor enhancement Improvements on existing features refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant