diff --git a/src/components/LabelControls.vue b/src/components/LabelControls.vue index 7c656155..c5e671ee 100644 --- a/src/components/LabelControls.vue +++ b/src/components/LabelControls.vue @@ -42,8 +42,22 @@ const editingLabel = computed(() => { return props.labelsStore.labels[editingLabelID.value]; }); +const makeUniqueName = (name: string) => { + const existingNames = new Set( + Object.values(props.labelsStore.labels).map((label) => label.labelName) + ); + let uniqueName = name; + let i = 1; + while (existingNames.has(uniqueName)) { + uniqueName = `${name} (${i})`; + i++; + } + return uniqueName; +}; + const createLabel = () => { - editingLabelID.value = props.labelsStore.addLabel(); + const labelName = makeUniqueName('New Label'); + editingLabelID.value = props.labelsStore.addLabel({ labelName }); }; function startEditing(label: LabelID) { @@ -114,6 +128,7 @@ function deleteEditingLabel() { @delete="deleteEditingLabel" @cancel="stopEditing(false)" @done="stopEditing(true)" + :labelsStore="labelsStore" /> diff --git a/src/components/ToolLabelEditor.vue b/src/components/ToolLabelEditor.vue index 9415e0d0..c1e72c30 100644 --- a/src/components/ToolLabelEditor.vue +++ b/src/components/ToolLabelEditor.vue @@ -1,5 +1,8 @@