Skip to content

Commit 339eefe

Browse files
committed
fix: don't allow to add duplicate alias to the group
1 parent 8e61470 commit 339eefe

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

l10n/bundle.l10n.zh-cn.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@
3030
"Import json file successfully": "json文件导入成功",
3131
"No any alias need to import": "没有数据需要导入",
3232
"Fail to read file: {message}": "文件读取失败: {message}",
33-
"Fail to resolve json file: {message}": "json文件解析失败: {message}"
33+
"Fail to resolve json file: {message}": "json文件解析失败: {message}",
34+
"This alias already exists": "此别名已存在"
3435
}

src/extension.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ alias ${alias}`,
594594
return
595595
}
596596

597-
const groups = this.globalState.keys().filter((key) => ![SYSTEM_ALIAS, alias.group].includes(key))
597+
const groups = this.globalState.keys().filter((group) => ![SYSTEM_ALIAS, alias.group].includes(group))
598598
if (groups.length === 0) {
599599
vscode.window.showWarningMessage('No any group can be added')
600600
return
@@ -610,6 +610,12 @@ alias ${alias}`,
610610
}
611611

612612
const aliases = normalizeAliasesToArray<Alias>(this.globalState.get(selectedGroup))
613+
const hasSameAlias = aliases.some((aliasItem) => isSameAlias(alias.data!, aliasItem))
614+
if (hasSameAlias) {
615+
vscode.window.showInformationMessage(vscode.l10n.t('This alias already exists'))
616+
return
617+
}
618+
613619
aliases.push(alias.data)
614620
this.globalState.update(selectedGroup, aliases)
615621

0 commit comments

Comments
 (0)