Skip to content

Commit

Permalink
Revert "Support a persistent option for widgets"
Browse files Browse the repository at this point in the history
This reverts commit 522bacc. The
feature, as designed there, cannot really work due to the way range
sets optimize mapping of deleted chunks.

See https://discuss.codemirror.net/t/mapmode-simple-for-block-widget-decorations/9040/3
  • Loading branch information
marijnh committed Feb 27, 2025
1 parent 522bacc commit 441d528
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/decoration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ interface WidgetDecorationSpec {
/// [`requestMeasure`](#view.EditorView.requestMeasure), so that the
/// editor can update its information about its vertical layout.
block?: boolean
/// By default, widgets get removed, during mapping, when the
/// content around them is deleted. Set this to true to make a
/// widget survive such changes.
persistent?: boolean
/// Other properties are allowed.
[other: string]: any
}
Expand Down Expand Up @@ -243,7 +239,7 @@ export abstract class Decoration extends RangeValue {
side += (block && !spec.inlineOrder)
? (side > 0 ? Side.BlockAfter : Side.BlockBefore)
: (side > 0 ? Side.InlineAfter : Side.InlineBefore)
return new PointDecoration(spec, side, side, block, !!spec.persistent, spec.widget || null, false)
return new PointDecoration(spec, side, side, block, spec.widget || null, false)
}

/// Create a replace decoration which replaces the given range with
Expand All @@ -258,7 +254,7 @@ export abstract class Decoration extends RangeValue {
startSide = (start ? (block ? Side.BlockIncStart : Side.InlineIncStart) : Side.NonIncStart) - 1
endSide = (end ? (block ? Side.BlockIncEnd : Side.InlineIncEnd) : Side.NonIncEnd) + 1
}
return new PointDecoration(spec, startSide, endSide, block, false, spec.widget || null, true)
return new PointDecoration(spec, startSide, endSide, block, spec.widget || null, true)
}

/// Create a line decoration, which can add DOM attributes to the
Expand Down Expand Up @@ -336,14 +332,10 @@ export class PointDecoration extends Decoration {
constructor(spec: any,
startSide: number, endSide: number,
public block: boolean,
persistent: boolean,
widget: WidgetType | null,
readonly isReplace: boolean) {
super(startSide, endSide, widget, spec)
this.mapMode = persistent ? MapMode.Simple
: !block ? MapMode.TrackDel
: startSide <= 0 ? MapMode.TrackBefore
: MapMode.TrackAfter
this.mapMode = !block ? MapMode.TrackDel : startSide <= 0 ? MapMode.TrackBefore : MapMode.TrackAfter
}

// Only relevant when this.block == true
Expand Down

0 comments on commit 441d528

Please sign in to comment.