Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
5044744a
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5044744a
编写于
5月 17, 2018
作者:
K
Krzysztof Cieslak
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add more separators and support for trailing zeros
上级
a707e00f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
97 addition
and
6 deletion
+97
-6
src/vs/workbench/parts/files/electron-browser/fileActions.ts
src/vs/workbench/parts/files/electron-browser/fileActions.ts
+13
-6
src/vs/workbench/parts/files/test/electron-browser/fileActions.test.ts
...nch/parts/files/test/electron-browser/fileActions.test.ts
+84
-0
未找到文件。
src/vs/workbench/parts/files/electron-browser/fileActions.ts
浏览文件 @
5044744a
...
@@ -1059,15 +1059,22 @@ function findValidPasteFileTarget(targetFolder: ExplorerItem, fileToPaste: { res
...
@@ -1059,15 +1059,22 @@ function findValidPasteFileTarget(targetFolder: ExplorerItem, fileToPaste: { res
}
}
export
function
incrementFileName
(
name
:
string
,
isFolder
:
boolean
):
string
{
export
function
incrementFileName
(
name
:
string
,
isFolder
:
boolean
):
string
{
const
separators
=
'
[
\\
.
\\
-_]
'
;
// file.1.txt=>file.2.txt
// file.1.txt=>file.2.txt
if
(
!
isFolder
&&
name
.
match
(
/
(
.*
\.)(\d
+
)(\.
.*
)
$/
))
{
let
suffixFileRegex
=
RegExp
(
'
(.*
'
+
separators
+
'
)(
\\
d+)(
\\
..*)$
'
);
return
name
.
replace
(
/
(
.*
\.)(\d
+
)(\.
.*
)
$/
,
(
match
,
g1
?,
g2
?,
g3
?)
=>
{
return
g1
+
(
parseInt
(
g2
)
+
1
)
+
g3
;
});
if
(
!
isFolder
&&
name
.
match
(
suffixFileRegex
))
{
return
name
.
replace
(
suffixFileRegex
,
(
match
,
g1
?,
g2
?,
g3
?)
=>
{
return
g1
+
strings
.
pad
(
parseInt
(
g2
)
+
1
,
g2
.
length
)
+
g3
;
});
}
}
// 1.file.txt=>2.file.txt
// 1.file.txt=>2.file.txt
if
(
!
isFolder
&&
name
.
match
(
/
(\d
+
)(\.
.*
)(\.
.*
)
$/
))
{
let
prefixFileRegex
=
RegExp
(
'
(
\\
d+)(
'
+
separators
+
'
.*)(
\\
..*)$
'
);
return
name
.
replace
(
/
(\d
+
)(\.
.*
)(\.
.*
)
$/
,
(
match
,
g1
?,
g2
?,
g3
?)
=>
{
return
(
parseInt
(
g1
)
+
1
)
+
g2
+
g3
;
});
if
(
!
isFolder
&&
name
.
match
(
prefixFileRegex
))
{
return
name
.
replace
(
prefixFileRegex
,
(
match
,
g1
?,
g2
?,
g3
?)
=>
{
return
strings
.
pad
(
parseInt
(
g1
)
+
1
,
g1
.
length
)
+
g2
+
g3
;
});
}
}
// file.txt=>file.1.txt
// file.txt=>file.1.txt
...
@@ -1078,12 +1085,12 @@ export function incrementFileName(name: string, isFolder: boolean): string {
...
@@ -1078,12 +1085,12 @@ export function incrementFileName(name: string, isFolder: boolean): string {
// folder.1=>folder.2
// folder.1=>folder.2
if
(
isFolder
&&
name
.
match
(
/
(\d
+
)
$/
))
{
if
(
isFolder
&&
name
.
match
(
/
(\d
+
)
$/
))
{
return
name
.
replace
(
/
(\d
+
)
$/
,
(
match
:
string
,
...
groups
:
any
[])
=>
{
return
String
(
parseInt
(
groups
[
0
])
+
1
);
});
return
name
.
replace
(
/
(\d
+
)
$/
,
(
match
:
string
,
...
groups
:
any
[])
=>
{
return
strings
.
pad
(
parseInt
(
groups
[
0
])
+
1
,
groups
[
0
].
length
);
});
}
}
// 1.folder=>2.folder
// 1.folder=>2.folder
if
(
isFolder
&&
name
.
match
(
/^
(\d
+
)
/
))
{
if
(
isFolder
&&
name
.
match
(
/^
(\d
+
)
/
))
{
return
name
.
replace
(
/^
(\d
+
)
/
,
(
match
:
string
,
...
groups
:
any
[])
=>
{
return
String
(
parseInt
(
groups
[
0
])
+
1
);
});
return
name
.
replace
(
/^
(\d
+
)
/
,
(
match
:
string
,
...
groups
:
any
[])
=>
{
return
strings
.
pad
(
parseInt
(
groups
[
0
])
+
1
,
groups
[
0
].
length
);
});
}
}
// file/folder=>file.1/folder.1
// file/folder=>file.1/folder.1
...
...
src/vs/workbench/parts/files/test/electron-browser/fileActions.test.ts
浏览文件 @
5044744a
...
@@ -28,22 +28,106 @@ suite('Files - Increment file name', () => {
...
@@ -28,22 +28,106 @@ suite('Files - Increment file name', () => {
assert
.
strictEqual
(
result
,
'
test.2.js
'
);
assert
.
strictEqual
(
result
,
'
test.2.js
'
);
});
});
test
(
'
Increment file name with suffix version with trailing zeros
'
,
function
()
{
const
name
=
'
test.001.js
'
;
const
result
=
incrementFileName
(
name
,
false
);
assert
.
strictEqual
(
result
,
'
test.002.js
'
);
});
test
(
'
Increment file name with suffix version with trailing zeros, changing length
'
,
function
()
{
const
name
=
'
test.009.js
'
;
const
result
=
incrementFileName
(
name
,
false
);
assert
.
strictEqual
(
result
,
'
test.010.js
'
);
});
test
(
'
Increment file name with suffix version with `-` as separator
'
,
function
()
{
const
name
=
'
test-1.js
'
;
const
result
=
incrementFileName
(
name
,
false
);
assert
.
strictEqual
(
result
,
'
test-2.js
'
);
});
test
(
'
Increment file name with suffix version with `-` as separator, trailing zeros
'
,
function
()
{
const
name
=
'
test-001.js
'
;
const
result
=
incrementFileName
(
name
,
false
);
assert
.
strictEqual
(
result
,
'
test-002.js
'
);
});
test
(
'
Increment file name with suffix version with `-` as separator, trailing zeros, changnig length
'
,
function
()
{
const
name
=
'
test-099.js
'
;
const
result
=
incrementFileName
(
name
,
false
);
assert
.
strictEqual
(
result
,
'
test-100.js
'
);
});
test
(
'
Increment file name with suffix version with `_` as separator
'
,
function
()
{
const
name
=
'
test_1.js
'
;
const
result
=
incrementFileName
(
name
,
false
);
assert
.
strictEqual
(
result
,
'
test_2.js
'
);
});
test
(
'
Increment folder name with suffix version
'
,
function
()
{
test
(
'
Increment folder name with suffix version
'
,
function
()
{
const
name
=
'
test.1
'
;
const
name
=
'
test.1
'
;
const
result
=
incrementFileName
(
name
,
true
);
const
result
=
incrementFileName
(
name
,
true
);
assert
.
strictEqual
(
result
,
'
test.2
'
);
assert
.
strictEqual
(
result
,
'
test.2
'
);
});
});
test
(
'
Increment folder name with suffix version, trailing zeros
'
,
function
()
{
const
name
=
'
test.001
'
;
const
result
=
incrementFileName
(
name
,
true
);
assert
.
strictEqual
(
result
,
'
test.002
'
);
});
test
(
'
Increment folder name with suffix version with `-` as separator
'
,
function
()
{
const
name
=
'
test-1
'
;
const
result
=
incrementFileName
(
name
,
true
);
assert
.
strictEqual
(
result
,
'
test-2
'
);
});
test
(
'
Increment folder name with suffix version with `_` as separator
'
,
function
()
{
const
name
=
'
test_1
'
;
const
result
=
incrementFileName
(
name
,
true
);
assert
.
strictEqual
(
result
,
'
test_2
'
);
});
test
(
'
Increment file name with prefix version
'
,
function
()
{
test
(
'
Increment file name with prefix version
'
,
function
()
{
const
name
=
'
1.test.js
'
;
const
name
=
'
1.test.js
'
;
const
result
=
incrementFileName
(
name
,
false
);
const
result
=
incrementFileName
(
name
,
false
);
assert
.
strictEqual
(
result
,
'
2.test.js
'
);
assert
.
strictEqual
(
result
,
'
2.test.js
'
);
});
});
test
(
'
Increment file name with prefix version, trailing zeros
'
,
function
()
{
const
name
=
'
001.test.js
'
;
const
result
=
incrementFileName
(
name
,
false
);
assert
.
strictEqual
(
result
,
'
002.test.js
'
);
});
test
(
'
Increment file name with prefix version with `-` as separator
'
,
function
()
{
const
name
=
'
1-test.js
'
;
const
result
=
incrementFileName
(
name
,
false
);
assert
.
strictEqual
(
result
,
'
2-test.js
'
);
});
test
(
'
Increment file name with prefix version with `-` as separator
'
,
function
()
{
const
name
=
'
1_test.js
'
;
const
result
=
incrementFileName
(
name
,
false
);
assert
.
strictEqual
(
result
,
'
2_test.js
'
);
});
test
(
'
Increment folder name with suffix version
'
,
function
()
{
test
(
'
Increment folder name with suffix version
'
,
function
()
{
const
name
=
'
1.test
'
;
const
name
=
'
1.test
'
;
const
result
=
incrementFileName
(
name
,
true
);
const
result
=
incrementFileName
(
name
,
true
);
assert
.
strictEqual
(
result
,
'
2.test
'
);
assert
.
strictEqual
(
result
,
'
2.test
'
);
});
});
test
(
'
Increment folder name with suffix version, trailing zeros
'
,
function
()
{
const
name
=
'
001.test
'
;
const
result
=
incrementFileName
(
name
,
true
);
assert
.
strictEqual
(
result
,
'
002.test
'
);
});
test
(
'
Increment folder name with suffix version with `-` as separator
'
,
function
()
{
const
name
=
'
1-test
'
;
const
result
=
incrementFileName
(
name
,
true
);
assert
.
strictEqual
(
result
,
'
2-test
'
);
});
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录