Skip to content

Commit

Permalink
Fix selection updates on decoration changes
Browse files Browse the repository at this point in the history
FIX: Make sure the selection is repositioned when a transaction
changes decorations without changing the document.

FEATURE: Layers now take a `updateOnDocUpdate` option that controls
whether they are automatically updated when the document view changes.

Issue dxos/dxos#5821
  • Loading branch information
marijnh committed Mar 4, 2024
1 parent 524ef55 commit 1b4b9dc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ interface LayerConfig {
/// Called on every view update. Returning true triggers a marker
/// update (a call to `markers` and drawing of those markers).
update(update: ViewUpdate, layer: HTMLElement): boolean
/// Whether to update this layer every time the document view
/// changes. Defaults to true.
updateOnDocViewUpdate: boolean
/// Build a set of markers for this layer, and measure their
/// dimensions.
markers(view: EditorView): readonly LayerMarker[]
Expand Down Expand Up @@ -241,6 +244,10 @@ class LayerView {
}
}

docViewUpdate(view: EditorView) {
if (this.layer.updateOnDocViewUpdate !== false) view.requestMeasure(this.measureReq)
}

setOrder(state: EditorState) {
let pos = 0, order = state.facet(layerOrder)
while (pos < order.length && order[pos] != this.layer) pos++
Expand Down

0 comments on commit 1b4b9dc

Please sign in to comment.