|
@@ -897,19 +897,19 @@ export const atomicDecorations = (options: Options) => {
|
|
|
return Decoration.set(decorations, true)
|
|
return Decoration.set(decorations, true)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let previousTree: Tree
|
|
|
|
|
-
|
|
|
|
|
return [
|
|
return [
|
|
|
StateField.define<{
|
|
StateField.define<{
|
|
|
mousedown: boolean
|
|
mousedown: boolean
|
|
|
decorations: DecorationSet
|
|
decorations: DecorationSet
|
|
|
|
|
+ previousTree: Tree
|
|
|
}>({
|
|
}>({
|
|
|
create(state) {
|
|
create(state) {
|
|
|
- previousTree = syntaxTree(state)
|
|
|
|
|
|
|
+ const previousTree = syntaxTree(state)
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
mousedown: false,
|
|
mousedown: false,
|
|
|
decorations: createDecorations(state, previousTree),
|
|
decorations: createDecorations(state, previousTree),
|
|
|
|
|
+ previousTree,
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
update(value, tr) {
|
|
update(value, tr) {
|
|
@@ -917,33 +917,35 @@ export const atomicDecorations = (options: Options) => {
|
|
|
// store the "mousedown" value when it changes
|
|
// store the "mousedown" value when it changes
|
|
|
if (effect.is(mouseDownEffect)) {
|
|
if (effect.is(mouseDownEffect)) {
|
|
|
value = {
|
|
value = {
|
|
|
|
|
+ ...value,
|
|
|
mousedown: effect.value,
|
|
mousedown: effect.value,
|
|
|
- decorations: value.decorations, // unchanged
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const tree = syntaxTree(tr.state)
|
|
const tree = syntaxTree(tr.state)
|
|
|
if (
|
|
if (
|
|
|
- tree.type === previousTree.type &&
|
|
|
|
|
|
|
+ tree.type === value.previousTree.type &&
|
|
|
tree.length < tr.state.doc.length
|
|
tree.length < tr.state.doc.length
|
|
|
) {
|
|
) {
|
|
|
// still parsing
|
|
// still parsing
|
|
|
value = {
|
|
value = {
|
|
|
- mousedown: value.mousedown, // unchanged
|
|
|
|
|
|
|
+ ...value,
|
|
|
decorations: value.decorations.map(tr.changes),
|
|
decorations: value.decorations.map(tr.changes),
|
|
|
}
|
|
}
|
|
|
} else if (
|
|
} else if (
|
|
|
// only update the decorations when the mouse is not making a selection
|
|
// only update the decorations when the mouse is not making a selection
|
|
|
!value.mousedown &&
|
|
!value.mousedown &&
|
|
|
- (tree !== previousTree || tr.selection || hasMouseDownEffect(tr))
|
|
|
|
|
|
|
+ (tree !== value.previousTree ||
|
|
|
|
|
+ tr.selection ||
|
|
|
|
|
+ hasMouseDownEffect(tr))
|
|
|
) {
|
|
) {
|
|
|
// tree changed
|
|
// tree changed
|
|
|
- previousTree = tree
|
|
|
|
|
// TODO: update the existing decorations for the changed range(s)?
|
|
// TODO: update the existing decorations for the changed range(s)?
|
|
|
value = {
|
|
value = {
|
|
|
- mousedown: value.mousedown, // unchanged
|
|
|
|
|
|
|
+ ...value,
|
|
|
decorations: createDecorations(tr.state, tree),
|
|
decorations: createDecorations(tr.state, tree),
|
|
|
|
|
+ previousTree: tree,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|