Add duplicate (^D), basic search, bugfixes

* Use ^D to duplicate array items
* Use / to search, matching keys will be highlighted
* Don't attempt to load non-existing files when passed on command line
This commit is contained in:
2024-10-08 11:04:26 +02:00
parent 1f74bbfc0d
commit ca61374654
4 changed files with 87 additions and 26 deletions

View File

@@ -146,21 +146,21 @@ class Editor
break;
// FIXME make sure this clones; editing a clone updates original as well
// case 'd':
// $node = $this->list->getNodeForIndex($this->currentRow);
// $coll = $this->list->findNearestCollection($this->currentRow, true);
// if (!$coll)
// break;
// $collNode = $this->list->getNodeForIndex($coll);
// if ($collNode instanceof ArrayNode) {
// $collNode->append(clone $node);
// $this->list->parseTree();
// $this->redrawEditor();
// } else {
// $this->term->setCursor(1, $h);
// echo "\e[97;41mCan only duplicate in arrays, node={$this->currentRow}, coll={$coll}\e[K\e[0m";
// }
// break;
case "\x04": // ctrl-d
$node = $this->list->getNodeForIndex($this->currentRow);
$coll = $this->list->findNearestCollection($this->currentRow, true);
if (!$coll)
break;
$collNode = $this->list->getNodeForIndex($coll);
if ($collNode instanceof ArrayNode) {
$collNode->append(clone $node);
$this->modified = true;
$this->list->parseTree();
$this->redrawEditor();
} else {
$this->showMessage("\e[97;41mCan only duplicate in arrays");
}
break;
case 'I':
$this->doInsertMenu();
@@ -259,6 +259,10 @@ class Editor
$this->showMessage("Toggle compact groups (c)");
break;
case "/":
$this->doSearch();
break;
case "\x0d": // enter
$node = $this->list->getNodeForIndex($this->currentRow);
if ($node instanceof ValueNode) {
@@ -343,12 +347,25 @@ class Editor
Settings::save(SETTINGS_FILE);
// for ($n = 0; $n < 20; $n++) {
// $this->currentRow = $n;
// $this->redrawEditor();
// sleep(1);
// }
}
public function doSearch(): void
{
$search = $this->ask("\e[36mSearch: ");
if ($search === null) {
$this->redrawEditor();
return;
}
if ($search === '') {
$this->list->searchResults = [];
} else {
$this->list->searchResults = $this->document->search($search);
}
$this->redrawEditor();
}
/**
@@ -1063,6 +1080,7 @@ To get started, press I (shift-i) and add something to the document. Use the arr
E Edit selected key
Enter Edit string/number, toggle booleans
D Delete selected key
^D Duplicate array item
c Toggle compact list view
q Toggle quoted keys in list view
g Toggle indentation guide lines visibility