@@ -4,7 +4,7 @@ import { WorkspaceProvider } from '../../../context/providers/workspace-provider
44import type { Checkpoint } from '../types'
55import { copy_workspace_to_dir } from './copy-workspace-to-dir'
66import { get_checkpoints } from './get-checkpoints'
7- import { get_checkpoint_path } from '../utils'
7+ import { get_checkpoint_path , get_incremented_description } from '../utils'
88
99export const create_checkpoint = async (
1010 workspace_provider : WorkspaceProvider ,
@@ -29,37 +29,20 @@ export const create_checkpoint = async (
2929 await copy_workspace_to_dir ( checkpoint_dir_uri , workspace_provider )
3030
3131 const checkpoints = await get_checkpoints ( context )
32- let final_description = description
33- if ( title == 'Created by user' && description === undefined ) {
34- const user_checkpoints = checkpoints . filter (
35- ( c ) => c . title == 'Created by user'
36- )
37- const first_custom_index = user_checkpoints . findIndex (
38- ( c ) => ! c . description ?. match ( / ^ \( \d + \) $ / )
39- )
4032
41- const relevant_checkpoints =
42- first_custom_index === - 1
43- ? user_checkpoints
44- : user_checkpoints . slice ( 0 , first_custom_index )
45-
46- const user_checkpoint_numbers = relevant_checkpoints . map ( ( c ) =>
47- parseInt ( c . description ! . match ( / ^ \( ( \d + ) \) $ / ) ! [ 1 ] , 10 )
48- )
33+ const final_description = get_incremented_description (
34+ title ,
35+ description ,
36+ checkpoints
37+ )
4938
50- const max_num =
51- user_checkpoint_numbers . length > 0
52- ? Math . max ( ...user_checkpoint_numbers )
53- : 0
54- final_description = `(${ max_num + 1 } )`
55- }
5639 const new_checkpoint : Checkpoint = {
5740 title,
5841 timestamp,
5942 description : final_description
6043 }
6144
62- checkpoints . push ( new_checkpoint )
45+ checkpoints . unshift ( new_checkpoint )
6346 await context . workspaceState . update ( CHECKPOINTS_STATE_KEY , checkpoints )
6447 }
6548 )
0 commit comments