Prevent duplicate/overwritten keys
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace NoccyLabs\JsonEdit\Editor;
|
||||
|
||||
use Exception;
|
||||
use NoccyLabs\JsonEdit\List\TreeList;
|
||||
use NoccyLabs\JsonEdit\Settings;
|
||||
use NoccyLabs\JsonEdit\Terminal\Terminal;
|
||||
@@ -590,10 +591,14 @@ class Editor
|
||||
if ($parent->node instanceof ObjectNode) {
|
||||
$newVal = $this->ask("\e[0;33mnew key:\e[0m ", $entry->key);
|
||||
if (!empty($newVal)) {
|
||||
$parent->node->rename($entry->key, $newVal);
|
||||
$entry->key = $newVal;
|
||||
$this->list->parseTree();
|
||||
$this->redrawEditor();
|
||||
try {
|
||||
$parent->node->rename($entry->key, $newVal);
|
||||
$entry->key = $newVal;
|
||||
$this->redrawEditor();
|
||||
} catch (Exception $e) {
|
||||
$this->redrawEditor();
|
||||
$this->showMessage("\e[97;41m".$e->getMessage());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// $this->term->setCursor(1, $h);
|
||||
@@ -679,6 +684,10 @@ class Editor
|
||||
$this->redrawInfoBar();
|
||||
return;
|
||||
}
|
||||
if ($node->hasKey($key)) {
|
||||
$this->showMessage("\e[97;41mThe key {$key} already exists");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($value === null)
|
||||
|
||||
Reference in New Issue
Block a user