diff --git a/HISTORY.md b/HISTORY.md index f48907f4..7dd296ea 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,7 +4,8 @@ ## unpublished changes since version 10.1.0 -- Fix: upgrade to the latest version of `ace`. +- Fix: when editing a key giving it a ` (copy)` suffix, the suffix was removed. +- Fix: upgrade to the latest version of `ace`. ## 2024-06-19, version 10.1.0 diff --git a/src/js/util.js b/src/js/util.js index 30605857..15e21216 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -1021,6 +1021,10 @@ export function get (object, path) { * @param {Array} existingPropNames Array with existing prop names */ export function findUniqueName (name, existingPropNames) { + if (existingPropNames.indexOf(name) === -1) { + return name + } + const strippedName = name.replace(/ \(copy( \d+)?\)$/, '') let validName = strippedName let i = 1 diff --git a/test/util.test.js b/test/util.test.js index 46095fae..23437ec9 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -376,6 +376,11 @@ describe('util', () => { 'b (copy 2)', 'c' ]), 'b (copy 3)') + + assert.strictEqual(findUniqueName('b (copy)', [ + 'a', + 'c' + ]), 'b (copy)') }) it('should format a document size in a human readable way', () => {