File tree 3 files changed +11
-4
lines changed
3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -213,9 +213,10 @@ const handleNewProblem = async (problem: Problem) => {
213
213
214
214
// Add fields absent in competitive companion.
215
215
problem . srcPath = srcPath ;
216
- problem . tests = problem . tests . map ( ( testcase ) => ( {
216
+ problem . tests = problem . tests . map ( ( testcase , index ) => ( {
217
217
...testcase ,
218
- id : randomId ( ) ,
218
+ // Pass in index to avoid generating duplicate id
219
+ id : randomId ( index ) ,
219
220
} ) ) ;
220
221
if ( ! existsSync ( srcPath ) ) {
221
222
writeFileSync ( srcPath , '' ) ;
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ const createLocalProblem = async (editor: vscode.TextEditor) => {
64
64
url : srcPath ,
65
65
tests : [
66
66
{
67
- id : randomId ( ) ,
67
+ id : randomId ( null ) ,
68
68
input : '' ,
69
69
output : '' ,
70
70
} ,
Original file line number Diff line number Diff line change @@ -164,7 +164,13 @@ export const ocHide = () => {
164
164
oc . hide ( ) ;
165
165
} ;
166
166
167
- export const randomId = ( ) => Math . floor ( Date . now ( ) + Math . random ( ) * 100 ) ;
167
+ export const randomId = ( index : number | null ) => {
168
+ if ( index !== null ) {
169
+ return Math . floor ( Date . now ( ) + index ) ;
170
+ } else {
171
+ return Math . floor ( Date . now ( ) + Math . random ( ) * 100 ) ;
172
+ }
173
+ } ;
168
174
169
175
/**
170
176
* Check if file is supported. If not, shows an error dialog. Returns true if
You can’t perform that action at this time.
0 commit comments