-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2513 from codecrafters-io/code-mirror/update-cm-m…
…erge Update `@codemirror/merge` to version `6.8.0`
- Loading branch information
Showing
9 changed files
with
170 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
app/utils/code-mirror-collapse-unchanged-gutter-widget-class.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { EditorView, GutterMarker, gutterWidgetClass } from '@codemirror/view'; | ||
|
||
export class CollapseUnchangedGutterMarker extends GutterMarker { | ||
elementClass = 'cm-collapseUnchangedBarNeighbor'; | ||
|
||
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; | ||
} | ||
} | ||
|
||
export function collapseUnchangedGutterWidgetClass() { | ||
return gutterWidgetClass.of(function (_view, widget, _block): GutterMarker | null { | ||
if ('type' in widget && widget.type === 'collapsed-unchanged-code') { | ||
return new CollapseUnchangedGutterMarker(); | ||
} | ||
|
||
return null; | ||
}); | ||
} |
Oops, something went wrong.