@@ -12,6 +12,9 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
1212 return ViewPlugin . fromClass (
1313 class {
1414 decorations : DecorationSet ;
15+ /**
16+ * Component for unloading the widgets if the view plugin is destroyed.
17+ */
1518 component : Component ;
1619
1720 constructor ( view : EditorView ) {
@@ -20,6 +23,12 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
2023 this . decorations = this . renderWidgets ( view ) ?? Decoration . none ;
2124 }
2225
26+ /**
27+ * Triggered by codemirror when the view updates.
28+ * Depending on the update type, the decorations are either updated or recreated.
29+ *
30+ * @param update
31+ */
2332 update ( update : ViewUpdate ) : void {
2433 // only activate in LP and not source mode
2534 // @ts -ignore some strange private field not being assignable
@@ -41,6 +50,11 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
4150 }
4251 }
4352
53+ /**
54+ * Updates all the widgets by traversing the syntax tree.
55+ *
56+ * @param view
57+ */
4458 updateTree ( view : EditorView ) : void {
4559 for ( const { from, to } of view . visibleRanges ) {
4660 syntaxTree ( view . state ) . iterate ( {
@@ -70,6 +84,11 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
7084 }
7185 }
7286
87+ /**
88+ * Removes all decorations at a given node.
89+ *
90+ * @param node
91+ */
7392 removeDecoration ( node : SyntaxNode ) : void {
7493 this . decorations . between ( node . from - 1 , node . to + 1 , ( from , to , _ ) => {
7594 this . decorations = this . decorations . update ( {
@@ -80,6 +99,14 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
8099 } ) ;
81100 }
82101
102+ /**
103+ * Adds a widget at a given node if it does not exist yet.
104+ *
105+ * @param node the note where to add the widget
106+ * @param view
107+ * @param content the content of the node
108+ * @param widgetType the type of the widget to add
109+ */
83110 addDecoration ( node : SyntaxNode , view : EditorView , content : string , widgetType : MBWidgetType ) : void {
84111 const from = node . from - 1 ;
85112 const to = node . to + 1 ;
@@ -106,7 +133,7 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
106133 }
107134
108135 /**
109- * return weather to render the widget and the type of the widget to render.
136+ * Checks whether to render a widget at a given node and the type of the widget to render.
110137 *
111138 * @param view
112139 * @param node
@@ -137,7 +164,7 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
137164 }
138165
139166 /**
140- * reads the node, returning its content and widgetType .
167+ * Reads the content of an editor range and checks if it is a declaration if so also returning the widget type .
141168 *
142169 * @param view
143170 * @param from
@@ -155,6 +182,11 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
155182 } ;
156183 }
157184
185+ /**
186+ * Completely re-renders all widgets.
187+ *
188+ * @param view
189+ */
158190 renderWidgets ( view : EditorView ) : RangeSet < Decoration > | undefined {
159191 const currentFile = Cm6_Util . getCurrentFile ( view ) ;
160192 if ( ! currentFile ) {
@@ -192,6 +224,14 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
192224 return Decoration . set ( widgets , true ) ;
193225 }
194226
227+ /**
228+ * Renders a singe widget of the given widget type at a given node.
229+ *
230+ * @param node
231+ * @param widgetType
232+ * @param content
233+ * @param currentFile
234+ */
195235 renderWidget (
196236 node : SyntaxNode ,
197237 widgetType : MBWidgetType ,
@@ -214,6 +254,10 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
214254 } ) . range ( node . from - 1 , node . to + 1 ) ;
215255 }
216256
257+ /**
258+ * Triggered by codemirror when the view plugin is destroyed.
259+ * Unloads all widgets.
260+ */
217261 destroy ( ) : void {
218262 this . component . unload ( ) ;
219263 }
0 commit comments