Skip to content

Commit

Permalink
Merge pull request #50869 from Krzysztof-Cieslak/fix50820
Browse files Browse the repository at this point in the history
Add support for `1.txt` format in incrementFileName
  • Loading branch information
isidorn committed Jun 4, 2018
2 parents 8e95a31 + 7510fcb commit e0140fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/vs/workbench/parts/files/electron-browser/fileActions.ts
Expand Up @@ -1083,6 +1083,17 @@ export function incrementFileName(name: string, isFolder: boolean): string {
});
}

// 1.txt=>2.txt
let prefixFileNoNameRegex = RegExp('(\\d+)(\\..*)$');
if (!isFolder && name.match(prefixFileNoNameRegex)) {
return name.replace(prefixFileNoNameRegex, (match, g1?, g2?) => {
let number = parseInt(g1);
return number < maxNumber
? strings.pad(number + 1, g1.length) + g2
: strings.format('{0}.1{1}', g1, g2);
});
}

// file.txt=>file.1.txt
const lastIndexOfDot = name.lastIndexOf('.');
if (!isFolder && lastIndexOfDot >= 0) {
Expand Down
Expand Up @@ -106,6 +106,18 @@ suite('Files - Increment file name', () => {
assert.strictEqual(result, '2.test.js');
});

test('Increment file name with just version in name', function () {
const name = '1.js';
const result = incrementFileName(name, false);
assert.strictEqual(result, '2.js');
});

test('Increment file name with just version in name, too big number', function () {
const name = '9007199254740992.js';
const result = incrementFileName(name, false);
assert.strictEqual(result, '9007199254740992.1.js');
});

test('Increment file name with prefix version, trailing zeros', function () {
const name = '001.test.js';
const result = incrementFileName(name, false);
Expand Down

0 comments on commit e0140fa

Please sign in to comment.