Let `handleChangeKey` fire the change event
This commit is contained in:
parent
a0aaf206fa
commit
dfe7c06ec7
|
@ -103,17 +103,7 @@
|
||||||
|
|
||||||
function updateKey () {
|
function updateKey () {
|
||||||
const newKey = getPlainText(domKey)
|
const newKey = getPlainText(domKey)
|
||||||
|
|
||||||
// TODO: replace the onChangeKey callback with gobally managed JSONNode id's,
|
|
||||||
// which are kept in sync with the json itself using JSONPatch
|
|
||||||
onChangeKey(newKey, key)
|
onChangeKey(newKey, key)
|
||||||
|
|
||||||
const parentPath = getParentPath()
|
|
||||||
onChange([{
|
|
||||||
op: 'move',
|
|
||||||
from: compileJSONPointer(parentPath.concat(key)),
|
|
||||||
path: compileJSONPointer(parentPath.concat(newKey))
|
|
||||||
}])
|
|
||||||
}
|
}
|
||||||
const updateKeyDebounced = debounce(updateKey, DEBOUNCE_DELAY)
|
const updateKeyDebounced = debounce(updateKey, DEBOUNCE_DELAY)
|
||||||
|
|
||||||
|
@ -195,6 +185,7 @@
|
||||||
|
|
||||||
function handleChangeKey (newChildKey, oldChildKey) {
|
function handleChangeKey (newChildKey, oldChildKey) {
|
||||||
if (type === 'object') {
|
if (type === 'object') {
|
||||||
|
// we need to make sure that the renamed property will keep the same id
|
||||||
const index = props.findIndex(item => item.key === oldChildKey)
|
const index = props.findIndex(item => item.key === oldChildKey)
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
// we use splice here to replace the old key with the new new one
|
// we use splice here to replace the old key with the new new one
|
||||||
|
@ -207,6 +198,13 @@
|
||||||
key: newChildKey
|
key: newChildKey
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const path = getPath()
|
||||||
|
onChange([{
|
||||||
|
op: 'move',
|
||||||
|
from: compileJSONPointer(path.concat(oldChildKey)),
|
||||||
|
path: compileJSONPointer(path.concat(newChildKey))
|
||||||
|
}])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue