aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/editor/scrollbarViewPlugin.ts
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/frontend/src/editor/scrollbarViewPlugin.ts')
-rw-r--r--subprojects/frontend/src/editor/scrollbarViewPlugin.ts22
1 files changed, 8 insertions, 14 deletions
diff --git a/subprojects/frontend/src/editor/scrollbarViewPlugin.ts b/subprojects/frontend/src/editor/scrollbarViewPlugin.ts
index 0edaeb70..b0ea769f 100644
--- a/subprojects/frontend/src/editor/scrollbarViewPlugin.ts
+++ b/subprojects/frontend/src/editor/scrollbarViewPlugin.ts
@@ -2,6 +2,7 @@ import { type PluginValue, ViewPlugin } from '@codemirror/view';
2import { reaction } from 'mobx'; 2import { reaction } from 'mobx';
3 3
4import type EditorStore from './EditorStore'; 4import type EditorStore from './EditorStore';
5import { getDiagnostics } from './exposeDiagnostics';
5import findOccurrences from './findOccurrences'; 6import findOccurrences from './findOccurrences';
6 7
7export const HOLDER_CLASS = 'cm-scroller-holder'; 8export const HOLDER_CLASS = 'cm-scroller-holder';
@@ -105,11 +106,12 @@ export default function scrollbarViewPlugin(
105 const annotations: HTMLDivElement[] = []; 106 const annotations: HTMLDivElement[] = [];
106 107
107 function rebuildAnnotations(trackYHeight: number) { 108 function rebuildAnnotations(trackYHeight: number) {
109 const { state } = view;
108 const annotationOverlayHeight = Math.min( 110 const annotationOverlayHeight = Math.min(
109 view.contentHeight, 111 view.contentHeight,
110 trackYHeight, 112 trackYHeight,
111 ); 113 );
112 const lineHeight = annotationOverlayHeight / editorStore.state.doc.lines; 114 const lineHeight = annotationOverlayHeight / state.doc.lines;
113 115
114 let i = 0; 116 let i = 0;
115 117
@@ -117,11 +119,9 @@ export default function scrollbarViewPlugin(
117 from: number, 119 from: number,
118 to?: number, 120 to?: number,
119 ): HTMLDivElement { 121 ): HTMLDivElement {
120 const startLine = editorStore.state.doc.lineAt(from).number; 122 const startLine = state.doc.lineAt(from).number;
121 const endLine = 123 const endLine =
122 to === undefined 124 to === undefined ? startLine : state.doc.lineAt(to).number;
123 ? startLine
124 : editorStore.state.doc.lineAt(to).number;
125 const top = (startLine - 1) * lineHeight; 125 const top = (startLine - 1) * lineHeight;
126 const height = Math.max( 126 const height = Math.max(
127 MIN_ANNOTATION_HEIGHT, 127 MIN_ANNOTATION_HEIGHT,
@@ -145,13 +145,13 @@ export default function scrollbarViewPlugin(
145 return annotation; 145 return annotation;
146 } 146 }
147 147
148 editorStore.state.selection.ranges.forEach(({ head }) => { 148 state.selection.ranges.forEach(({ head }) => {
149 const selectionAnnotation = getOrCreateAnnotation(head); 149 const selectionAnnotation = getOrCreateAnnotation(head);
150 selectionAnnotation.className = ANNOTATION_SELECTION_CLASS; 150 selectionAnnotation.className = ANNOTATION_SELECTION_CLASS;
151 selectionAnnotation.style.width = `${SCROLLBAR_WIDTH}px`; 151 selectionAnnotation.style.width = `${SCROLLBAR_WIDTH}px`;
152 }); 152 });
153 153
154 const diagnosticsIter = editorStore.diagnostics.iter(); 154 const diagnosticsIter = getDiagnostics(state).iter();
155 while (diagnosticsIter.value !== null) { 155 while (diagnosticsIter.value !== null) {
156 const diagnosticAnnotation = getOrCreateAnnotation( 156 const diagnosticAnnotation = getOrCreateAnnotation(
157 diagnosticsIter.from, 157 diagnosticsIter.from,
@@ -162,7 +162,7 @@ export default function scrollbarViewPlugin(
162 diagnosticsIter.next(); 162 diagnosticsIter.next();
163 } 163 }
164 164
165 const occurrences = editorStore.state.field(findOccurrences); 165 const occurrences = view.state.field(findOccurrences);
166 const occurrencesIter = occurrences.iter(); 166 const occurrencesIter = occurrences.iter();
167 while (occurrencesIter.value !== null) { 167 while (occurrencesIter.value !== null) {
168 const occurrenceAnnotation = getOrCreateAnnotation( 168 const occurrenceAnnotation = getOrCreateAnnotation(
@@ -259,15 +259,9 @@ export default function scrollbarViewPlugin(
259 259
260 requestRebuild(); 260 requestRebuild();
261 261
262 const disposeRebuildReaction = reaction(
263 () => editorStore.diagnostics,
264 requestRebuild,
265 );
266
267 return { 262 return {
268 update: requestRebuild, 263 update: requestRebuild,
269 destroy() { 264 destroy() {
270 disposeRebuildReaction();
271 disposePanelReaction(); 265 disposePanelReaction();
272 observer?.disconnect(); 266 observer?.disconnect();
273 scrollDOM.removeEventListener('scroll', requestUpdate); 267 scrollDOM.removeEventListener('scroll', requestUpdate);