@@ -47,7 +47,21 @@ export class ListItem {
4747 this . taskLocation = taskLocation ;
4848 }
4949
50- public static fromListItemLine ( originalMarkdown : string , parent : ListItem | null , taskLocation : TaskLocation ) {
50+ /**
51+ * Takes the given line from an Obsidian note and returns a ListItem object.
52+ *
53+ * @static
54+ * @param {string } originalMarkdown - The full line in the note to parse.
55+ * @param {ListItem | null } parent - The optional parent Task or ListItem of the new instance.
56+ * @param {TaskLocation } taskLocation - The location of the ListItem.
57+ * @return {ListItem | null }
58+ * @see Task.fromLine
59+ */
60+ public static fromListItemLine (
61+ originalMarkdown : string ,
62+ parent : ListItem | null ,
63+ taskLocation : TaskLocation ,
64+ ) : ListItem | null {
5165 const nonTaskMatch = RegExp ( TaskRegularExpressions . nonTaskRegex ) . exec ( originalMarkdown ) ;
5266 let indentation = '' ;
5367 let listMarker = '' ;
@@ -207,13 +221,25 @@ export class ListItem {
207221 }
208222
209223 public checkOrUncheck ( ) : ListItem {
224+ if ( this . statusCharacter === null ) {
225+ return this ;
226+ }
227+
210228 const newStatusCharacter = this . statusCharacter === ' ' ? 'x' : ' ' ;
211229 const newMarkdown = this . originalMarkdown . replace (
212230 RegExp ( TaskRegularExpressions . checkboxRegex ) ,
213231 `[${ newStatusCharacter } ]` ,
214232 ) ;
215233
216- return ListItem . fromListItemLine ( newMarkdown , null , this . taskLocation ) ;
234+ return new ListItem ( {
235+ ...this ,
236+ originalMarkdown : newMarkdown ,
237+ statusCharacter : newStatusCharacter ,
238+ // The purpose of this method is just to update the status character on one single line in the file.
239+ // This will trigger an update, making Cache re-read the whole file,
240+ // which will then identify and re-create any parent-child relationships.
241+ parent : null ,
242+ } ) ;
217243 }
218244
219245 public toFileLineString ( ) : string {
0 commit comments