11import  *  as  vscode  from  'vscode' ; 
22import  {  Position ,  Range ,  TextEditorEdit  }  from  'vscode' ; 
33import  *  as  helpers  from  './helpers' ; 
4+ const  moment  =  require ( 'moment' ) ; 
45
56/** Mark a checkbox as checked or unchecked */ 
67export  const  toggleCheckbox  =  async  ( )  =>  { 
@@ -69,10 +70,12 @@ const markField = (checkboxPosition: Position, replacement: string): Thenable<bo
6970        const  foundTrailingWhitespace  =  lineText . substr ( checkboxPosition . character  +  4 ,  lineText . length ) . match ( / [ \s \n \r ] * $ / ) ; 
7071        const  whitespace  =  foundTrailingWhitespace  ? foundTrailingWhitespace . join ( '' )  : '' ; 
7172
73+         const  dateFormat  =  helpers . getConfig < string > ( 'dateFormat' ) ; 
74+ 
7275        if  ( ! lhc . checked  &&  textWithoutCheckbox . length  >  0 )  { 
7376            let  newText  =  ( strikeThroughWhenChecked  ? '~~'  : '' )  +  ( italicWhenChecked  ? '*'  : '' )  +  textWithoutCheckbox  +  ( italicWhenChecked  ? '*'  : '' )  +  ( strikeThroughWhenChecked  ? '~~'  : '' ) ; 
7477            // add the date string 
75-             newText  =  newText  +  ( dateWhenChecked  ? ' ['  +  helpers . getDateString ( new  Date ( ) )  +  ']'  : '' )  +  whitespace ; 
78+             newText  =  newText  +  ( dateWhenChecked  ? ' ['  +  moment ( new  Date ( ) ) . format ( dateFormat )  +  ']'  : '' )  +  whitespace ; 
7679
7780            editBuilder . replace ( new  Range ( 
7881                new  Position ( checkboxPosition . line ,  checkboxPosition . character  +  4 ) , 
@@ -82,7 +85,9 @@ const markField = (checkboxPosition: Position, replacement: string): Thenable<bo
8285        else  if  ( lhc . checked )  { 
8386            let  newText  =  textWithoutCheckbox . replace ( / ~ ~ / g,  '' ) . replace ( / \* / g,  '' ) ; 
8487            // remove the date string 
85-             newText  =  newText . replace ( / \s + \[ \d { 4 } [ \- ] \d { 2 } [ \- ] \d { 2 } \] \s * / ,  '' )  +  whitespace ; 
88+             if  ( dateWhenChecked )  { 
89+                 newText  =  newText . replace ( / \s + \[ [ \s \S ] + \] $ / ,  '' )  +  whitespace ; 
90+             } 
8691
8792            editBuilder . replace ( new  Range ( 
8893                new  Position ( checkboxPosition . line ,  checkboxPosition . character  +  4 ) , 
0 commit comments