Skip to content

AskAI extension#272

Merged
Bistard merged 51 commits intodevfrom
dev-ask-AI
Feb 25, 2025
Merged

AskAI extension#272
Bistard merged 51 commits intodevfrom
dev-ask-AI

Conversation

@Bistard
Copy link
Owner

@Bistard Bistard commented Feb 18, 2025

Pull Request Template

Environment Changes

  • ...

Breaking Changes

  • ...

Features

  • ...

Fixes

  • ...

Checklist

  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Summary by Sourcery

This pull request introduces a block handle extension that allows users to drag and drop blocks of text within the editor. It also adds a block insert palette that provides quick insertion of various document block types at the current cursor position. The slash command extension is refactored to use the new block insert palette.

New Features:

  • Introduces a block handle extension that allows users to drag and drop blocks of text within the editor.
  • Adds a block insert palette that provides quick insertion of various document block types at the current cursor position.

Enhancements:

  • Refactors the slash command extension to use the new block insert palette.
  • Improves the drag and drop experience by adding a drop cursor and scroll on edge functionality.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 18, 2025

Reviewer's Guide by Sourcery

This pull request introduces the AskAI extension, which includes a block handle extension with drag and drop functionality, slash command extension refactoring, and several file relocation and renaming operations. Additionally, it fixes a bug in event emitter disposal and updates the regular expression for localization.

Sequence diagram for showing slash command

sequenceDiagram
    participant Editor as Editor
    participant EditorSlashCommandExtension as SlashCommand
    participant BlockInsertPalette as Palette

    Editor->>SlashCommand: onTextInput(e)
    SlashCommand->SlashCommand: __tryShowSlashCommand(e)
    alt isCursor && isEmptyBlock && isSlash
        SlashCommand->Palette: render(position)
        activate Palette
        Palette-->>SlashCommand: Menu shown
        deactivate Palette
        SlashCommand->Editor: view.focus()
    else not (isCursor && isEmptyBlock && isSlash)
        SlashCommand-->>Editor: return
    end
Loading

Sequence diagram for adding a block using the block handle

sequenceDiagram
    participant Editor as Editor
    participant EditorBlockHandleExtension as BlockHandle
    participant AddBlockButton as Button
    participant ProseEditorView as View

    Editor->>BlockHandle: onMouseMove(e)
    BlockHandle->BlockHandle: _renderController.request({ event: e })
    BlockHandle->BlockHandle: renderWidget(container, nodePosition, nodeElement)
    BlockHandle->>Button: onDidClick()
    Button->>View: view.dispatch(newTr)
    View-->>Button: Update view
    Button->>BlockHandle: extension.renderPalette(domPosition)
    BlockHandle->>BlockInsertPalette: render(position)
    activate BlockInsertPalette
    BlockInsertPalette-->>BlockHandle: Palette shown
    deactivate BlockInsertPalette
    BlockHandle->>View: view.focus()
Loading

Updated class diagram for EditorSlashCommandExtension

classDiagram
    class EditorSlashCommandExtension {
        - _palette: BlockInsertPalette
        + constructor(editorWidget: IEditorWidget, instantiationService: IInstantiationService)
        - __tryShowSlashCommand(e: IOnTextInputEvent): void
    }
    EditorExtension <|-- EditorSlashCommandExtension
    EditorSlashCommandExtension -- BlockInsertPalette : uses
Loading

Class diagram for BlockInsertPalette

classDiagram
    class BlockInsertPalette {
        - _menuRenderer: SlashMenuRenderer
        - _menuController: SlashMenuController
        - _keyboardController: SlashKeyboardController
        + constructor(editorWidget: IEditorWidget, contextMenuService: IContextMenuService, i18nService: II18nService)
        + render(position: IPosition): void
        + focusPrev(): void
        + focusNext(): void
        + getFocus(): number
        + getAction(indexOrID: number | string): MenuAction | undefined
        + tryOpenSubmenu(): boolean
        + hasFocus(): boolean
        + destroy(): void
        + runFocus(): void
    }
    Disposable <|-- BlockInsertPalette
    BlockInsertPalette -- SlashMenuRenderer : uses
    BlockInsertPalette -- SlashMenuController : uses
    BlockInsertPalette -- SlashKeyboardController : uses

    class SlashMenuRenderer {

    }

    class SlashMenuController {

    }

    class SlashKeyboardController {

    }

    class Disposable {

    }

    class MenuAction {

    }

    class IPosition {

    }
Loading

Class diagram for EditorBlockHandleExtension

classDiagram
    class EditorBlockHandleExtension {
        - _currDropPosition?: number
        - _widget?: IWidgetBar
        - _renderController: RequestAnimateController
        - _paletteRenderer: PaletteRenderer
        + constructor(editorWidget: IEditorWidget, instantiationService: IInstantiationService)
        + unrenderWidget(): void
        + renderWidget(container: HTMLElement, nodePosition: number, nodeElement: HTMLElement): void
        + renderPalette(position: IPosition): void
        - __renderWidgetWithoutTarget(e: IEditorMouseEvent): void
        - __initWidget(view: ProseEditorView): IWidgetBar
    }
    EditorExtension <|-- EditorBlockHandleExtension
    EditorBlockHandleExtension -- PaletteRenderer : uses
    EditorBlockHandleExtension -- IWidgetBar : uses

    class PaletteRenderer {
        - _palette: BlockInsertPalette
        + constructor(editorWidget: IEditorWidget, instantiationService: IInstantiationService)
        + render(position: IPosition): void
        + destroy(): void
    }
    Disposable <|-- PaletteRenderer

    class IWidgetBar {

    }

    class RequestAnimateController {

    }

    class IPosition {

    }

    class IEditorMouseEvent {

    }

    class ProseEditorView {

    }

    class EditorExtension {

    }

    class BlockInsertPalette {

    }

    class Disposable {

    }
Loading

File-Level Changes

Change Details Files
Refactor slash command extension to use BlockInsertPalette directly and move BlockInsertPalette to the view layer.
  • Removed the slash command scss import from the slashCommandExtension.
  • Moved BlockInsertPalette to the view layer.
  • Modified EditorSlashCommandExtension to directly use BlockInsertPalette.
  • Removed SlashKeyboardController and SlashMenuController.
  • Updated EditorSlashCommandExtension to use IInstantiationService to create BlockInsertPalette.
src/editor/view/widget/blockInsertPalette/blockInsertPalette.ts
src/editor/contrib/slashCommand/slashCommand.ts
Rename and relocate drag and drop extension files.
  • Renamed EditorDragAndDropExtension to EditorDragAndDropExtension.
  • Moved drag and drop extension files to a new directory.
  • Updated import paths in related files.
src/editor/contrib/dragAndDrop/dragAndDrop.ts
src/editor/contrib/dragAndDrop/dropBlinkRenderer.ts
src/editor/contrib/dragAndDrop/dropCursorRenderer.ts
src/editor/contrib/dragAndDrop/scrollOnEdgeController.ts
Rename and relocate input rule extension files.
  • Renamed EditorInputRuleExtension to EditorInputRuleExtension.
  • Moved input rule extension files to a new directory.
  • Updated import paths in related files.
src/editor/contrib/inputRule/editorInputRules.ts
src/editor/contrib/inputRule/inputRule.ts
Rename and relocate command extension files.
  • Renamed EditorCommandExtension to EditorCommandExtension.
  • Moved command extension files to a new directory.
  • Updated import paths in related files.
src/editor/contrib/command/command.ts
src/editor/contrib/command/editorCommands.ts
Implement block handle extension with drag and drop functionality.
  • Created a new block handle extension with associated scss file.
  • Implemented drag and drop functionality for blocks.
  • Added a widget bar for block manipulation.
  • Implemented a palette renderer for block insertion.
  • Added drag handle and add block buttons.
src/editor/contrib/blockHandle/blockHandle.ts
Fix a bug in event emitter disposal.
  • Modified the event emitter to properly dispose of priority queues.
src/base/common/event.ts
Update regular expression for localization to improve accuracy.
  • Created a new file to store the regular expression.
  • Updated the regular expression to improve accuracy.
scripts/i18n/i18n.js
scripts/i18n/localizeRegExp.js

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

@Bistard Bistard changed the base branch from master to dev February 18, 2025 18:17
@Bistard Bistard merged commit 9e621c4 into dev Feb 25, 2025
5 checks passed
@Bistard Bistard deleted the dev-ask-AI branch February 25, 2025 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI core editor new feature new features or requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants