Skip to content

Commit

Permalink
Export a gutterWidgetClass facet
Browse files Browse the repository at this point in the history
FEATURE: The new `gutterWidgetClass` facet makes it possible to add a class
to gutter elements next to widgets.
  • Loading branch information
marijnh committed Aug 12, 2024
1 parent fa5cfc9 commit 4ce14c1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ example](../../examples/gutter/).

@gutterLineClass

@gutterWidgetClass

@lineNumberMarkers

@lineNumberWidgetMarker
Expand Down
13 changes: 11 additions & 2 deletions src/gutter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ GutterMarker.prototype.point = true
/// in all gutters for the line).
export const gutterLineClass = Facet.define<RangeSet<GutterMarker>>()

/// Facet used to add a class to all gutter elements next to a widget.
/// Should not provide widgets with a `toDOM` method.
export const gutterWidgetClass =
Facet.define<(view: EditorView, widget: WidgetType, block: BlockInfo) => GutterMarker | null>()

type Handlers = {[event: string]: (view: EditorView, line: BlockInfo, event: Event) => boolean}

interface GutterConfig {
Expand Down Expand Up @@ -272,8 +277,12 @@ class UpdateContext {
}

widget(view: EditorView, block: BlockInfo) {
let marker = this.gutter.config.widgetMarker(view, block.widget!, block)
if (marker) this.addElement(view, block, [marker])
let marker = this.gutter.config.widgetMarker(view, block.widget!, block), markers = marker ? [marker] : null
for (let cls of view.state.facet(gutterWidgetClass)) {
let marker = cls(view, block.widget!, block)
if (marker) (markers || (markers = [])).push(marker)
}
if (markers) this.addElement(view, block, markers)
}

finish() {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export {showTooltip, Tooltip, TooltipView, tooltips, getTooltip, hoverTooltip, H
closeHoverTooltips, repositionTooltips} from "./tooltip"
export {showPanel, PanelConstructor, Panel, getPanel, panels} from "./panel"
export {lineNumbers, highlightActiveLineGutter, gutter, gutters, GutterMarker,
gutterLineClass, lineNumberMarkers, lineNumberWidgetMarker} from "./gutter"
gutterLineClass, gutterWidgetClass, lineNumberMarkers, lineNumberWidgetMarker} from "./gutter"
export {highlightWhitespace, highlightTrailingWhitespace} from "./highlight-space"

import {HeightMap, HeightOracle, MeasuredHeights, QueryType, clearHeightChangeFlag, heightChangeFlag} from "./heightmap"
Expand Down

0 comments on commit 4ce14c1

Please sign in to comment.