Skip to content

Commit

Permalink
fix: when editing a key giving it a (copy) suffix, the suffix was …
Browse files Browse the repository at this point in the history
…removed
  • Loading branch information
josdejong committed Sep 25, 2024
1 parent 9651576 commit f66771f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit f66771f

Please sign in to comment.