From 55ba1ea4f94f19e6ccda41bfd94c86f676157daf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 12 Feb 2021 15:12:52 +0100 Subject: [PATCH 1/3] refactoring --- .../demos/Experiments/Annotation/extension/AnnotationState.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts b/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts index eede1f3c..c7615da8 100644 --- a/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts +++ b/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts @@ -100,7 +100,7 @@ export class AnnotationState { console.warn(`[${this.options.instance}] corrupt decoration `, annotation.from, from, annotation.to, to) } - return decorations.push( + decorations.push( Decoration.inline(from, to, HTMLAttributes, { id, data: annotation.data }), ) }) From 262a1c9815d52e8fe99622328a89116e397511ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 12 Feb 2021 15:13:40 +0100 Subject: [PATCH 2/3] set inclusiveEnd for decorations --- .../demos/Experiments/Annotation/extension/AnnotationState.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts b/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts index c7615da8..7127f042 100644 --- a/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts +++ b/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts @@ -101,7 +101,7 @@ export class AnnotationState { } decorations.push( - Decoration.inline(from, to, HTMLAttributes, { id, data: annotation.data }), + Decoration.inline(from, to, HTMLAttributes, { id, data: annotation.data, inclusiveEnd: true }), ) }) From 34af078be69bd458b68b24770fffbbf82e95a7c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 12 Feb 2021 15:54:05 +0100 Subject: [PATCH 3/3] refactoring --- .../Annotation/extension/AnnotationState.ts | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts b/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts index 7127f042..ed2cd1af 100644 --- a/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts +++ b/docs/src/demos/Experiments/Annotation/extension/AnnotationState.ts @@ -83,27 +83,24 @@ export class AnnotationState { const { doc, type, binding } = ystate const decorations: Decoration[] = [] - Array - .from(map.keys()) - .forEach(id => { - const annotation = map.get(id) - const from = relativePositionToAbsolutePosition(doc, type, annotation.from, binding.mapping) - const to = relativePositionToAbsolutePosition(doc, type, annotation.to, binding.mapping) + map.forEach((annotation, id) => { + const from = relativePositionToAbsolutePosition(doc, type, annotation.from, binding.mapping) + const to = relativePositionToAbsolutePosition(doc, type, annotation.to, binding.mapping) - if (!from || !to) { - return - } + if (!from || !to) { + return + } - console.log(`[${this.options.instance}] Decoration.inline()`, from, to, HTMLAttributes, { id, data: annotation.data }) + console.log(`[${this.options.instance}] Decoration.inline()`, from, to, HTMLAttributes, { id, data: annotation.data }) - if (from === to) { - console.warn(`[${this.options.instance}] corrupt decoration `, annotation.from, from, annotation.to, to) - } + if (from === to) { + console.warn(`[${this.options.instance}] corrupt decoration `, annotation.from, from, annotation.to, to) + } - decorations.push( - Decoration.inline(from, to, HTMLAttributes, { id, data: annotation.data, inclusiveEnd: true }), - ) - }) + decorations.push( + Decoration.inline(from, to, HTMLAttributes, { id, data: annotation.data, inclusiveEnd: true }), + ) + }) this.decorations = DecorationSet.create(state.doc, decorations) }