Skip to content

feat(markup): lineNumbers extension#1112

Draft
saxumcordis wants to merge 2 commits intomainfrom
line_numbers
Draft

feat(markup): lineNumbers extension#1112
saxumcordis wants to merge 2 commits intomainfrom
line_numbers

Conversation

@saxumcordis
Copy link
Copy Markdown
Contributor

@saxumcordis saxumcordis commented Apr 30, 2026

Preview

Summary by Sourcery

Add configurable line numbers and line highlighting support to the markup (CodeMirror) editor, and expose the related APIs and demos.

New Features:

  • Introduce a MarkupLineNumbersConfig option on the markup editor to enable line numbers, optional line highlighting, and initial highlighted ranges.
  • Add a scroll-to-line on mount capability for the markup editor via the line numbers configuration.
  • Expose line highlighting utilities (lineHighlight extension, LineRange, LineHighlightOptions, setHighlightedLine) from the editor package API.
  • Provide Storybook examples demonstrating markup line numbers, line highlighting, multi-line highlighting, and scroll-to-line behavior.

Enhancements:

  • Extend the CodeMirror gravity theme to style the gutters and line numbers for better visual integration.

@saxumcordis saxumcordis changed the title feat: add line numbers extension feat(markup): lineNumbers extension Apr 30, 2026
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 30, 2026

Reviewer's Guide

Implements a configurable CodeMirror-based line numbers and line-highlighting feature for the markup editor, wires it through the editor bundle API, styles it in the gravity theme, and adds demo Storybook examples plus public exports for consumers.

File-Level Changes

Change Details Files
Add configurable line numbers and line highlighting options to the markup editor configuration surface and plumb them through editor creation.
  • Introduce MarkupLineNumbersConfig with flags for enabling the gutter, line highlighting, initial selected range, click callback, and initial scroll line.
  • Extend MarkdownEditorMarkupConfig and CreateCodemirrorParams to accept the new lineNumbers configuration.
  • Expose markupConfig (and initialScrollToLine as a convenience getter) on the Editor implementation and pass lineNumbers through to createCodemirror.
packages/editor/src/bundle/types.ts
packages/editor/src/markup/codemirror/create.ts
packages/editor/src/bundle/Editor.ts
Implement CodeMirror line highlighting extension that integrates with line numbers and supports click-to-highlight plus programmatic control.
  • Create a lineHighlight extension that defines a highlighted line range StateField, a StateEffect (setHighlightedLine) to update it, and decorations for highlighted lines and gutter markers.
  • Configure a clickable lineNumbers gutter that toggles selection on click and calls an optional onLineClick callback with the clicked 0-based line number.
  • Export LineRange, LineHighlightOptions, lineHighlight, and setHighlightedLine from the markup codemirror module and the top-level editor index.
packages/editor/src/markup/codemirror/line-highlight/extension.ts
packages/editor/src/markup/codemirror/line-highlight/index.ts
packages/editor/src/markup/codemirror/index.ts
packages/editor/src/index.ts
Style line numbers and highlighted lines to match the Gravity theme.
  • Update gravityTheme to style CodeMirror gutters and line numbers (background, border, text color, padding/min-width).
  • Add theme rules in the lineHighlight extension for highlighted lines and gutter items, including pointer cursor on line numbers when clickable.
packages/editor/src/markup/codemirror/gravity.ts
packages/editor/src/markup/codemirror/line-highlight/extension.ts
Add scroll-to-line-on-mount behavior in markup React component using the new lineNumbers configuration.
  • Read markupConfig.lineNumbers.scrollToLine on mount and, when line numbers are enabled and a target line is provided, move the cursor to that line in the markup editor.
packages/editor/src/bundle/MarkupEditorComponent.tsx
Provide Storybook demos showcasing markup line numbers, highlighting, and scroll-to-line features.
  • Create a MarkupLineNumbersEditor example that configures the editor in markup mode with lineNumbers and wires onLineClick to local state.
  • Demonstrate programmatic highlighting via setHighlightedLine and clearing highlights using CM dispatch from the example UI.
  • Add Storybook stories to showcase line-numbers-only, highlight single line, highlight multiple lines, scroll-to-line, and combined features variants.
demo/src/stories/examples/markup-line-numbers/Editor.tsx
demo/src/stories/examples/markup-line-numbers/MarkupLineNumbers.stories.tsx

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!

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

@gravity-ui
Copy link
Copy Markdown

gravity-ui Bot commented Apr 30, 2026

Storybook Deployed

@gravity-ui
Copy link
Copy Markdown

gravity-ui Bot commented Apr 30, 2026

🎭 Playwright Report

saxumcordis added 2 commits April 30, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant