Skip to content
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

Update @codemirror/merge to version 6.8.0 #2513

Merged
merged 2 commits into from
Jan 9, 2025

Conversation

VasylMarchuk
Copy link
Collaborator

@VasylMarchuk VasylMarchuk commented Jan 4, 2025

Related to #1231

Brief

This updates @codemirror/merge from version 6.7.4 to version 6.8.0 and adjusts all the necessary styles.

Details

  • Updated @codemirror/merge plugin to version 6.8.0, changelog here
  • Removed all individual-page offset style hacks as they are no longer needed
  • Used a proper way of customizing the text of "Expand X unchanged lines" bar
  • Added a new util code-mirror-collapse-unchanged-gutter-widget-class — a custom extension used whenever originalDocument is passed:
    • it adds .cm-collapseUnchangedBarNeighbor class to all gutter elements that are next to the "Expand X unchanged lines" bar in the document
    • it renders .cm-collapseUnchangedBarGutterElement child elements inside the above gutter elements
    • the above child elements that appear inside .cm-changeGutter are:
      • covering the whole width of the gutter
      • have background, icons and hover state
      • respond to click events
    • it relays clicks on the gutter elements to the corresponding "Expand X unchanged lines" bars in the document
  • All the styles / themes have been adjusted for the new DOM structure, Dark Mode fixes included as well.

Demo

2025-01-03.18.49.11.mov
2025-01-03.18.52.47.mov

Checklist

  • I've thoroughly self-reviewed my changes
  • I've added tests for my changes, unless they affect admin-only areas (or are otherwise not worth testing)
  • I've verified any visual changes using Percy (add a commit with [percy] in the message to trigger)

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced diff editor with improved handling of unchanged lines.
    • Added ability to expand collapsed lines with clearer visual indicators.
  • Styling Updates

    • Refined CodeMirror gutter and line change styling.
    • Simplified collapsed lines hover effects.
    • Removed outdated styles related to course administration submissions and updates.
  • Dependency Update

    • Upgraded @codemirror/merge to version 6.8.0.
  • Performance

    • Optimized code diff visualization and interaction.

@VasylMarchuk VasylMarchuk added the enhancement New feature or request label Jan 4, 2025
@VasylMarchuk VasylMarchuk self-assigned this Jan 4, 2025
Copy link
Contributor

coderabbitai bot commented Jan 4, 2025

Walkthrough

This pull request introduces enhancements to the CodeMirror diff editor, focusing on improving the handling and visualization of unchanged lines. Key changes include the addition of a new gutter widget class for collapsing unchanged lines, updates to CSS styles for better visual representation, and modifications to the text displayed for collapsed lines. The changes span multiple files, including component logic, utility functions, and styling, aiming to provide a more intuitive user interface for code diffs.

Changes

File Change Summary
app/components/code-mirror.ts Added import for collapseUnchangedGutterWidgetClass and new phrase for expanding unchanged lines
app/styles/app.css Removed imports for course admin submission and updates diff CSS files
app/styles/pages/course-admin-submission-diff.css Deleted CSS file with margin styling for collapsed lines
app/styles/pages/course-admin-updates-diff.css Deleted CSS file with margin styling for collapsed lines
app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts Added new CollapseUnchangedGutterMarker class and collapseUnchangedGutterWidgetClass function
app/utils/code-mirror-themes.ts Updated CodeMirror styling for gutters, change indicators, and collapsed lines
package.json Updated @codemirror/merge dependency to version 6.8.0
tests/acceptance/course-admin/view-diffs-test.js Updated test assertions for collapsed lines text

Sequence Diagram

sequenceDiagram
    participant User
    participant Editor
    participant GutterWidget
    participant CollapsedLines

    User->>GutterWidget: Click collapse gutter
    GutterWidget->>Editor: Find corresponding collapsed area
    Editor->>CollapsedLines: Programmatically expand lines
    CollapsedLines-->>User: Display expanded content
Loading

Possibly related PRs

  • dark mode for course page [1/2] #2013: Enhances the dark mode experience on the course page, relevant to the main PR's updates on handling unchanged lines in the diff editor.
  • course dark mode #2024: Focuses on dark mode enhancements across various components, aligning with the main PR's goal of improving the diff editor's functionality.
  • add dark mode upgrade flow #2044: Modifications enhance dark mode styling for various components, relating to the main PR's updates on unchanged lines in the diff editor.
  • Add extensions dark mode styles #2045: Introduces dark mode styles across multiple components, relevant to the main PR's focus on enhancing the diff editor's visual aspects.

Poem

🐰 In CodeMirror's realm of lines,
Where diffs and changes intertwine,
A gutter click, a magic spell,
Expands the code and tells its tale!
Unchanged lines now dance with glee 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@VasylMarchuk VasylMarchuk changed the title Update to @codemirror/merge version 6.8.0 Update to @codemirror/merge to version 6.8.0 Jan 4, 2025
Copy link

github-actions bot commented Jan 4, 2025

Test Results

  1 files  ±  0    1 suites  +1   6m 0s ⏱️ + 6m 0s
595 tests +595  554 ✅ +554  41 💤 +41  0 ❌ ±0 
610 runs  +610  569 ✅ +569  41 💤 +41  0 ❌ ±0 

Results for commit 92d897d. ± Comparison against base commit 91f076c.

♻️ This comment has been updated with latest results.

Copy link

codecov bot commented Jan 4, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 9 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...e-mirror-collapse-unchanged-gutter-widget-class.ts 50.00% 9 Missing ⚠️
Additional details and impacted files

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts (1)

15-17: Validate element references before usage.

A null or undefined DOM element could cause runtime errors. For instance, editor, gutter, gutterElement, or gutterElementSiblings might be null. Currently, you safely return if they are missing, but coverage can be improved by testing these edge cases.

Would you like me to propose a test that confirms the code gracefully handles these null scenarios?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 16-16: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L16
Added line #L16 was not covered by tests

tests/acceptance/course-admin/view-diffs-test.js (1)

105-105: Ensure test coverage matches dynamic line counts.

Changing "⦚ 7 unchanged lines ⦚" to "Expand 7 unchanged lines" is consistent. If there's any logic that dynamically adjusts the displayed text, ensure test coverage remains updated for that logic.

app/utils/code-mirror-themes.ts (1)

195-225: Prudent approach for differentiating changed lines in Dark Mode.

Blending colors is a neat technique to maintain readability. Just confirm that the chosen colors pass accessibility guidelines (contrast ratio).

Would you like me to generate a script to help verify color contrast compliance?

app/components/code-mirror.ts (1)

402-404: Phrase addition for collapsed lines is user-friendly.

“Expand $ unchanged lines” conveys the action precisely. Great job providing a direct explanation instead of cryptic symbols.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91f076c and 7b038f4.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • app/components/code-mirror.ts (3 hunks)
  • app/styles/app.css (0 hunks)
  • app/styles/pages/course-admin-submission-diff.css (0 hunks)
  • app/styles/pages/course-admin-updates-diff.css (0 hunks)
  • app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts (1 hunks)
  • app/utils/code-mirror-themes.ts (6 hunks)
  • package.json (1 hunks)
  • tests/acceptance/course-admin/view-diffs-test.js (1 hunks)
💤 Files with no reviewable changes (3)
  • app/styles/app.css
  • app/styles/pages/course-admin-submission-diff.css
  • app/styles/pages/course-admin-updates-diff.css
🧰 Additional context used
🪛 GitHub Check: codecov/patch
app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts

[warning] 10-13: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L10-L13
Added lines #L10 - L13 were not covered by tests


[warning] 16-16: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L16
Added line #L16 was not covered by tests


[warning] 20-20: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L20
Added line #L20 was not covered by tests


[warning] 23-23: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L23
Added line #L23 was not covered by tests


[warning] 25-25: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L25
Added line #L25 was not covered by tests

🔇 Additional comments (11)
app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts (2)

9-13: Consider test coverage for the click event.

Currently, there's no test verifying that the click listener correctly locates and interacts with the corresponding expand bar in the content. Adding an acceptance or integration test can prevent regressions and confirm that this event-driven behavior works as intended.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 10-13: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L10-L13
Added lines #L10 - L13 were not covered by tests


32-40: Nice abstraction for creating a specialized gutter widget.

Returning null if the widget type doesn't match 'collapsed-unchanged-code' is a clean approach that avoids overhead. Just ensure test coverage exists to confirm that the gutter class is only assigned when needed.

tests/acceptance/course-admin/view-diffs-test.js (2)

93-93: Kudos on updating the placeholder text.

Switching to “Expand X unchanged lines” aligns with the new CodeMirror phrases. This ensures clarity for end-users.


99-99: Maintain consistent placeholders.

All placeholders now use the same “Expand X unchanged lines” format. Great move for consistency. If future placeholders differ, consider a constant or translation approach to maintain uniform text.

app/utils/code-mirror-themes.ts (4)

67-106: Great usage of Tailwind colors for branding consistency.

The newly introduced .cm-collapseUnchangedBarNeighbor style and its hover states use Tailwind color tokens, aligning well with the rest of the app. Ensure you account for the UI across different screen resolutions and color schemes.


Line range hint 113-128: Hover style improvements enhance discoverability.

Removing pseudo-elements and focusing on background/color changes is simpler and user-friendly. Good approach for maintaining a minimal and consistent design system.


Line range hint 227-242: Dark theme alignment with the new collapsed lines workflow.

Ensuring that .cm-collapsedLines and .cm-collapseUnchangedBarNeighbor are styled appropriately in dark mode prevents jarring user experiences. Looks well-structured.


130-136: Pseudo-elements removal looks tidy.

By removing :before and :after content, the code is more concise. Verify that related classes aren't depending on these pseudo-elements in older style sheets or code references.

✅ Verification successful

The previous search might have been too specific. Let's broaden it to find any usage of the class and any CSS files with pseudo-elements to ensure we don't miss any related styling.


Pseudo-element removal is safe to proceed

The search results show that all pseudo-element styles for the cm-collapsedLines class are contained within the same file (app/utils/code-mirror-themes.ts). The other pseudo-elements found in the file are for different styling purposes (showing "+" and "-" symbols) and are unrelated to the removed ones. There are no other dependencies on these pseudo-elements in other files or stylesheets.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching older references to cm-collapsedLines pseudo-elements
rg -A 3 "cm-collapsedLines:before|cm-collapsedLines:after"

Length of output: 60


Script:

#!/bin/bash
# Let's search for any references to cm-collapsedLines class in the codebase
rg -A 3 "cm-collapsedLines"

# Also search for any CSS/SCSS files that might contain pseudo-element styles
fd -e css -e scss -x rg -l "::before|::after|\:before|\:after" {}

Length of output: 2550


Script:

#!/bin/bash
# Let's try a different approach to find pseudo-element styles
# Search in the specific file and its directory for any pseudo-element references
rg -A 3 "(:before|:after|::before|::after)" "app/utils/code-mirror-themes.ts"
rg -A 3 "(:before|:after|::before|::after)" "app/utils/"

Length of output: 1308

app/components/code-mirror.ts (2)

40-40: Importing collapseUnchangedGutterWidgetClass.

This import cleanly integrates the new gutter widget extension. Make sure consumers of this component are aware of the new functionality to avoid confusion.


139-139: Optional extension pattern is tidy.

Wrapping collapseUnchangedGutterWidgetClass() in a conditional if originalDocument is provided ensures that the widget is only applied when relevant.

package.json (1)

42-42: LGTM! Verify test coverage for the new CodeMirror features.

The upgrade to @codemirror/merge@6.8.0 aligns with the PR objectives and maintains compatibility with other CodeMirror packages. The caret range (^6.8.0) appropriately allows for future patch updates while preventing breaking changes.

Run the test suite to ensure the new features work as expected:

@VasylMarchuk
Copy link
Collaborator Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jan 4, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts (1)

32-40: LGTM! Consider adding type safety improvements.

The utility function implementation is clean and follows CodeMirror's extension patterns.

Consider adding a type guard for better type safety:

+ interface CollapsedUnchangedWidget {
+   type: 'collapsed-unchanged-code';
+ }
+
+ function isCollapsedUnchangedWidget(widget: unknown): widget is CollapsedUnchangedWidget {
+   return typeof widget === 'object' && widget !== null && 'type' in widget &&
+          widget.type === 'collapsed-unchanged-code';
+ }
+
  export function collapseUnchangedGutterWidgetClass() {
    return gutterWidgetClass.of(function (_view, widget, _block): GutterMarker | null {
-     if ('type' in widget && widget.type === 'collapsed-unchanged-code') {
+     if (isCollapsedUnchangedWidget(widget)) {
        return new CollapseUnchangedGutterMarker();
      }
      return null;
    });
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b038f4 and 92d897d.

📒 Files selected for processing (7)
  • app/components/code-mirror.ts (3 hunks)
  • app/styles/app.css (0 hunks)
  • app/styles/pages/course-admin-submission-diff.css (0 hunks)
  • app/styles/pages/course-admin-updates-diff.css (0 hunks)
  • app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts (1 hunks)
  • app/utils/code-mirror-themes.ts (6 hunks)
  • tests/acceptance/course-admin/view-diffs-test.js (1 hunks)
💤 Files with no reviewable changes (3)
  • app/styles/pages/course-admin-submission-diff.css
  • app/styles/pages/course-admin-updates-diff.css
  • app/styles/app.css
🚧 Files skipped from review as they are similar to previous changes (3)
  • app/components/code-mirror.ts
  • tests/acceptance/course-admin/view-diffs-test.js
  • app/utils/code-mirror-themes.ts
🧰 Additional context used
🪛 GitHub Check: codecov/patch
app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts

[warning] 10-13: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L10-L13
Added lines #L10 - L13 were not covered by tests


[warning] 16-16: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L16
Added line #L16 was not covered by tests


[warning] 20-20: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L20
Added line #L20 was not covered by tests


[warning] 23-23: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L23
Added line #L23 was not covered by tests


[warning] 25-25: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L25
Added line #L25 was not covered by tests

🔇 Additional comments (2)
app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts (2)

1-4: LGTM! Clean class declaration with appropriate imports.

The class extends GutterMarker appropriately and follows consistent naming conventions.


6-29: Add unit tests for the click handler logic.

The click handler contains complex DOM traversal and event handling logic that should be tested. Static analysis indicates missing test coverage.

Would you like me to help create unit tests for this component? The tests should cover:

  1. Element creation and class assignment
  2. Click handler behavior with various DOM structures
  3. Error cases when elements are not found
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 10-13: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L10-L13
Added lines #L10 - L13 were not covered by tests


[warning] 16-16: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L16
Added line #L16 was not covered by tests


[warning] 20-20: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L20
Added line #L20 was not covered by tests


[warning] 23-23: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L23
Added line #L23 was not covered by tests


[warning] 25-25: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L25
Added line #L25 was not covered by tests

Comment on lines +6 to +29
toDOM(_view: EditorView): Node {
const el = document.createElement('div');
el.className = 'cm-collapseUnchangedBarGutterElement';
el.addEventListener('click', (_e) => {
const editor = el.closest('.cm-editor');
const gutter = el.closest('.cm-gutter');
const gutterElement = el.closest('.cm-collapseUnchangedBarNeighbor');
const gutterElementSiblings = gutter?.querySelectorAll('.cm-collapseUnchangedBarNeighbor');

if (!editor || !gutter || !gutterElement || !gutterElementSiblings) {
return;
}

// Find the index of the clicked gutter element
const gutterElementIndex = [...gutterElementSiblings.values()].indexOf(gutterElement);

// Find the corresponding expand unchanged bar in the content
const expandCollapsedBar = editor.querySelectorAll<HTMLElement>('.cm-content .cm-collapsedLines').item(gutterElementIndex);

expandCollapsedBar?.click();
});

return el;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using type-safe DOM queries and error handling.

The DOM manipulation code could be improved for better type safety and error handling:

  1. Replace querySelector with more specific type assertions
  2. Add error logging for failed DOM traversals
  3. Consider extracting the click handler logic for better testability

Here's a suggested improvement:

  toDOM(_view: EditorView): Node {
    const el = document.createElement('div');
    el.className = 'cm-collapseUnchangedBarGutterElement';
    el.addEventListener('click', (_e) => {
-     const editor = el.closest('.cm-editor');
-     const gutter = el.closest('.cm-gutter');
-     const gutterElement = el.closest('.cm-collapseUnchangedBarNeighbor');
-     const gutterElementSiblings = gutter?.querySelectorAll('.cm-collapseUnchangedBarNeighbor');
+     const editor = el.closest<HTMLElement>('.cm-editor');
+     const gutter = el.closest<HTMLElement>('.cm-gutter');
+     const gutterElement = el.closest<HTMLElement>('.cm-collapseUnchangedBarNeighbor');
 
      if (!editor || !gutter || !gutterElement) {
+       console.warn('Required DOM elements not found');
        return;
      }
 
+     const gutterElementSiblings = Array.from(
+       gutter.querySelectorAll<HTMLElement>('.cm-collapseUnchangedBarNeighbor')
+     );
+
      // Find the index of the clicked gutter element
-     const gutterElementIndex = [...gutterElementSiblings.values()].indexOf(gutterElement);
+     const gutterElementIndex = gutterElementSiblings.indexOf(gutterElement);
+     if (gutterElementIndex === -1) {
+       console.warn('Gutter element not found in siblings');
+       return;
+     }
 
      // Find the corresponding expand unchanged bar in the content
-     const expandCollapsedBar = editor.querySelectorAll<HTMLElement>('.cm-content .cm-collapsedLines').item(gutterElementIndex);
+     const expandCollapsedBars = editor.querySelectorAll<HTMLElement>(
+       '.cm-content .cm-collapsedLines'
+     );
+     const expandCollapsedBar = expandCollapsedBars[gutterElementIndex];
 
-     expandCollapsedBar?.click();
+     if (expandCollapsedBar) {
+       expandCollapsedBar.click();
+     } else {
+       console.warn('Corresponding collapsed bar not found');
+     }
    });

    return el;
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
toDOM(_view: EditorView): Node {
const el = document.createElement('div');
el.className = 'cm-collapseUnchangedBarGutterElement';
el.addEventListener('click', (_e) => {
const editor = el.closest('.cm-editor');
const gutter = el.closest('.cm-gutter');
const gutterElement = el.closest('.cm-collapseUnchangedBarNeighbor');
const gutterElementSiblings = gutter?.querySelectorAll('.cm-collapseUnchangedBarNeighbor');
if (!editor || !gutter || !gutterElement || !gutterElementSiblings) {
return;
}
// Find the index of the clicked gutter element
const gutterElementIndex = [...gutterElementSiblings.values()].indexOf(gutterElement);
// Find the corresponding expand unchanged bar in the content
const expandCollapsedBar = editor.querySelectorAll<HTMLElement>('.cm-content .cm-collapsedLines').item(gutterElementIndex);
expandCollapsedBar?.click();
});
return el;
}
toDOM(_view: EditorView): Node {
const el = document.createElement('div');
el.className = 'cm-collapseUnchangedBarGutterElement';
el.addEventListener('click', (_e) => {
const editor = el.closest<HTMLElement>('.cm-editor');
const gutter = el.closest<HTMLElement>('.cm-gutter');
const gutterElement = el.closest<HTMLElement>('.cm-collapseUnchangedBarNeighbor');
if (!editor || !gutter || !gutterElement) {
console.warn('Required DOM elements not found');
return;
}
const gutterElementSiblings = Array.from(
gutter.querySelectorAll<HTMLElement>('.cm-collapseUnchangedBarNeighbor')
);
// Find the index of the clicked gutter element
const gutterElementIndex = gutterElementSiblings.indexOf(gutterElement);
if (gutterElementIndex === -1) {
console.warn('Gutter element not found in siblings');
return;
}
// Find the corresponding expand unchanged bar in the content
const expandCollapsedBars = editor.querySelectorAll<HTMLElement>(
'.cm-content .cm-collapsedLines'
);
const expandCollapsedBar = expandCollapsedBars[gutterElementIndex];
if (expandCollapsedBar) {
expandCollapsedBar.click();
} else {
console.warn('Corresponding collapsed bar not found');
}
});
return el;
}
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 10-13: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L10-L13
Added lines #L10 - L13 were not covered by tests


[warning] 16-16: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L16
Added line #L16 was not covered by tests


[warning] 20-20: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L20
Added line #L20 was not covered by tests


[warning] 23-23: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L23
Added line #L23 was not covered by tests


[warning] 25-25: app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts#L25
Added line #L25 was not covered by tests

@VasylMarchuk VasylMarchuk changed the title Update to @codemirror/merge to version 6.8.0 Update @codemirror/merge to version 6.8.0 Jan 5, 2025
@VasylMarchuk VasylMarchuk merged commit bb6279d into main Jan 9, 2025
8 checks passed
@VasylMarchuk VasylMarchuk deleted the code-mirror/update-cm-merge branch January 9, 2025 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants