@@ -111,7 +111,7 @@ const createChoice = (overrides: Partial<ICaptureChoice> = {}): ICaptureChoice =
111111 prepend : false ,
112112 appendLink : false ,
113113 task : false ,
114- insertAfter : { enabled : false , after : '' , insertAtEnd : false , considerSubsections : false , createIfNotFound : false , createIfNotFoundLocation : '' } ,
114+ insertAfter : { enabled : false , after : '' , insertAtEnd : false , considerSubsections : false , createIfNotFound : false , createIfNotFoundLocation : '' , blankLineAfterMatchMode : 'auto' } ,
115115 newLineCapture : { enabled : false , direction : 'below' } ,
116116 openFile : false ,
117117 fileOpening : { location : 'tab' , direction : 'vertical' , mode : 'default' , focus : true } ,
@@ -205,7 +205,10 @@ describe('CaptureChoiceFormatter insert after blank lines', () => {
205205 return { formatter, file } ;
206206 } ;
207207
208- const createInsertAfterChoice = ( after : string ) : ICaptureChoice =>
208+ const createInsertAfterChoice = (
209+ after : string ,
210+ blankLineAfterMatchMode ?: 'auto' | 'skip' | 'none' ,
211+ ) : ICaptureChoice =>
209212 createChoice ( {
210213 insertAfter : {
211214 enabled : true ,
@@ -214,10 +217,11 @@ describe('CaptureChoiceFormatter insert after blank lines', () => {
214217 considerSubsections : false ,
215218 createIfNotFound : false ,
216219 createIfNotFoundLocation : '' ,
220+ blankLineAfterMatchMode,
217221 } ,
218222 } ) ;
219223
220- it ( 'skips one blank line after the match' , async ( ) => {
224+ it ( 'auto mode skips one blank line after a heading match' , async ( ) => {
221225 const { formatter, file } = createFormatter ( ) ;
222226 const choice = createInsertAfterChoice ( '# H' ) ;
223227 const fileContent = [ '# H' , '' , 'A' ] . join ( '\n' ) ;
@@ -232,7 +236,7 @@ describe('CaptureChoiceFormatter insert after blank lines', () => {
232236 expect ( result ) . toBe ( [ '# H' , '' , 'X' , 'A' ] . join ( '\n' ) ) ;
233237 } ) ;
234238
235- it ( 'skips multiple blank lines after the match' , async ( ) => {
239+ it ( 'auto mode skips multiple blank lines after a heading match' , async ( ) => {
236240 const { formatter, file } = createFormatter ( ) ;
237241 const choice = createInsertAfterChoice ( '# H' ) ;
238242 const fileContent = [ '# H' , '' , '' , 'A' ] . join ( '\n' ) ;
@@ -247,7 +251,7 @@ describe('CaptureChoiceFormatter insert after blank lines', () => {
247251 expect ( result ) . toBe ( [ '# H' , '' , '' , 'X' , 'A' ] . join ( '\n' ) ) ;
248252 } ) ;
249253
250- it ( 'treats whitespace-only lines as blank' , async ( ) => {
254+ it ( 'auto mode treats whitespace-only lines as blank' , async ( ) => {
251255 const { formatter, file } = createFormatter ( ) ;
252256 const choice = createInsertAfterChoice ( '# H' ) ;
253257 const fileContent = [ '# H' , ' \t' , 'A' ] . join ( '\n' ) ;
@@ -262,7 +266,7 @@ describe('CaptureChoiceFormatter insert after blank lines', () => {
262266 expect ( result ) . toBe ( [ '# H' , ' \t' , 'X' , 'A' ] . join ( '\n' ) ) ;
263267 } ) ;
264268
265- it ( 'keeps behavior unchanged when no blank lines follow' , async ( ) => {
269+ it ( 'auto mode keeps behavior unchanged when no blank lines follow' , async ( ) => {
266270 const { formatter, file } = createFormatter ( ) ;
267271 const choice = createInsertAfterChoice ( '# H' ) ;
268272 const fileContent = [ '# H' , 'A' ] . join ( '\n' ) ;
@@ -277,7 +281,7 @@ describe('CaptureChoiceFormatter insert after blank lines', () => {
277281 expect ( result ) . toBe ( [ '# H' , 'X' , 'A' ] . join ( '\n' ) ) ;
278282 } ) ;
279283
280- it ( 'keeps behavior unchanged when match is at EOF' , async ( ) => {
284+ it ( 'auto mode keeps behavior unchanged when match is at EOF' , async ( ) => {
281285 const { formatter, file } = createFormatter ( ) ;
282286 const choice = createInsertAfterChoice ( '# H' ) ;
283287 const fileContent = '# H' ;
@@ -292,7 +296,7 @@ describe('CaptureChoiceFormatter insert after blank lines', () => {
292296 expect ( result ) . toBe ( '# H\nX\n' ) ;
293297 } ) ;
294298
295- it ( 'handles CRLF content when skipping blank lines' , async ( ) => {
299+ it ( 'auto mode handles CRLF content when skipping blank lines' , async ( ) => {
296300 const { formatter, file } = createFormatter ( ) ;
297301 const choice = createInsertAfterChoice ( '# H' ) ;
298302 const fileContent = '# H\r\n\r\nA' ;
@@ -306,4 +310,49 @@ describe('CaptureChoiceFormatter insert after blank lines', () => {
306310
307311 expect ( result ) . toBe ( '# H\r\n\r\nX\nA' ) ;
308312 } ) ;
313+
314+ it ( 'auto mode does not skip blanks for non-heading matches' , async ( ) => {
315+ const { formatter, file } = createFormatter ( ) ;
316+ const choice = createInsertAfterChoice ( '- Item 1' ) ;
317+ const fileContent = [ '- Item 1' , '' , '- Item 2' ] . join ( '\n' ) ;
318+
319+ const result = await formatter . formatContentWithFile (
320+ 'X\n' ,
321+ choice ,
322+ fileContent ,
323+ file ,
324+ ) ;
325+
326+ expect ( result ) . toBe ( [ '- Item 1' , 'X' , '' , '- Item 2' ] . join ( '\n' ) ) ;
327+ } ) ;
328+
329+ it ( 'always skip mode skips blank lines after non-heading matches' , async ( ) => {
330+ const { formatter, file } = createFormatter ( ) ;
331+ const choice = createInsertAfterChoice ( '- Item 1' , 'skip' ) ;
332+ const fileContent = [ '- Item 1' , '' , '- Item 2' ] . join ( '\n' ) ;
333+
334+ const result = await formatter . formatContentWithFile (
335+ 'X\n' ,
336+ choice ,
337+ fileContent ,
338+ file ,
339+ ) ;
340+
341+ expect ( result ) . toBe ( [ '- Item 1' , '' , 'X' , '- Item 2' ] . join ( '\n' ) ) ;
342+ } ) ;
343+
344+ it ( 'never skip mode inserts immediately after the match' , async ( ) => {
345+ const { formatter, file } = createFormatter ( ) ;
346+ const choice = createInsertAfterChoice ( '# H' , 'none' ) ;
347+ const fileContent = [ '# H' , '' , 'A' ] . join ( '\n' ) ;
348+
349+ const result = await formatter . formatContentWithFile (
350+ 'X\n' ,
351+ choice ,
352+ fileContent ,
353+ file ,
354+ ) ;
355+
356+ expect ( result ) . toBe ( [ '# H' , 'X' , '' , 'A' ] . join ( '\n' ) ) ;
357+ } ) ;
309358} ) ;
0 commit comments