Improve prompts, treat invalid json as string on insert/edit
This commit is contained in:
		@@ -82,7 +82,7 @@ class Editor
 | 
			
		||||
                    $this->redrawEditor();
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'k{DOWN}':
 | 
			
		||||
                    $this->currentRow = min(count($this->list), $this->currentRow + 1);
 | 
			
		||||
                    $this->currentRow = min(count($this->list) - 1, $this->currentRow + 1);
 | 
			
		||||
                    $this->redrawEditor();
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'k{PGUP}':
 | 
			
		||||
@@ -102,7 +102,7 @@ class Editor
 | 
			
		||||
                    $parent = $this->list->getEntryForIndex($parentIndex);
 | 
			
		||||
                    
 | 
			
		||||
                    if ($parent->node instanceof ObjectNode) {
 | 
			
		||||
                        $newVal = $this->ask("\e[33;1mnew key:\e[0m ", $entry->key);
 | 
			
		||||
                        $newVal = $this->ask("\e[0;33mnew key:\e[0m ", $entry->key);
 | 
			
		||||
                        if ($newVal !== null) {
 | 
			
		||||
                            $entry->key = $newVal;
 | 
			
		||||
                            $this->redrawEditor();
 | 
			
		||||
@@ -121,6 +121,10 @@ class Editor
 | 
			
		||||
                        $newVal = $this->ask("\e[33;1mnew value:\e[0m ", $val);
 | 
			
		||||
                        if ($newVal !== null) {
 | 
			
		||||
                            $val = json_decode($newVal);
 | 
			
		||||
                            // If the string decodes to null, but isn't 'null', treat it as a string
 | 
			
		||||
                            if ($val === null && $newVal !== 'null') {
 | 
			
		||||
                                $val = $newVal;
 | 
			
		||||
                            }
 | 
			
		||||
                            $node->value = $val;
 | 
			
		||||
                            $this->redrawEditor();
 | 
			
		||||
                        } else {
 | 
			
		||||
@@ -287,7 +291,7 @@ class Editor
 | 
			
		||||
        $coll = $this->list->findNearestCollection($this->currentRow);
 | 
			
		||||
        $node = $this->list->getNodeForIndex($coll);
 | 
			
		||||
        if ($node instanceof ObjectNode) {
 | 
			
		||||
            $key = $this->ask("\e[97mkey:\e[0m ");
 | 
			
		||||
            $key = $this->ask("\e[0;33mkey:\e[0m ");
 | 
			
		||||
            if ($key === null) {
 | 
			
		||||
                $this->redrawInfoBar();
 | 
			
		||||
                return;
 | 
			
		||||
@@ -295,9 +299,15 @@ class Editor
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($value === null)
 | 
			
		||||
            $value = $this->ask("\e[97mvalue:\e[0m ");
 | 
			
		||||
            $value = $this->ask("\e[0;32mvalue:\e[0m ");
 | 
			
		||||
        if ($value !== null) {
 | 
			
		||||
            $value = json_decode($value);
 | 
			
		||||
            $newvalue = json_decode($value);
 | 
			
		||||
            // If the string decodes to null, but isn't 'null', treat it as a string
 | 
			
		||||
            if ($newvalue === null && $value !== 'null') {
 | 
			
		||||
                $newvalue = $value;
 | 
			
		||||
            }
 | 
			
		||||
            $value = $newvalue;
 | 
			
		||||
 | 
			
		||||
            $valueNode = match (true) {
 | 
			
		||||
                is_array($value) => new ArrayNode([]),
 | 
			
		||||
                is_object($value) => new ObjectNode([]),
 | 
			
		||||
@@ -411,10 +421,13 @@ class Editor
 | 
			
		||||
        $keys = [
 | 
			
		||||
            'e' => 'Edit',
 | 
			
		||||
            'E' => 'Edit key',
 | 
			
		||||
            'i' => 'Insert',
 | 
			
		||||
            'I' => 'Insert',
 | 
			
		||||
            'i' => 'Insert value',
 | 
			
		||||
            'D' => 'Delete',
 | 
			
		||||
            'C' => 'Copy',
 | 
			
		||||
            'P' => 'Paste',
 | 
			
		||||
            //'C' => 'Copy',
 | 
			
		||||
            //'P' => 'Paste',
 | 
			
		||||
            '^R' => 'Read',
 | 
			
		||||
            '^W' => 'Write',
 | 
			
		||||
            '^C' => 'Exit',
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user