From 467a47563bc3c485d8556a985dab0bab10407aa0 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Tue, 15 Oct 2019 11:26:46 +0000 Subject: [PATCH] console : if the suggested value is empty, do not use it but propose it as solution git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5584 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- console.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/console.php b/console.php index 257b1bb..b0296f1 100644 --- a/console.php +++ b/console.php @@ -323,6 +323,8 @@ class console $this->debug ("Autocompletion : start='$start', end='$end'"); $completeArr = call_user_func ($this->completionFunction, self::tokenize ($start)); + if (! is_array ($completeArr)) + throw new \Exception ("Autocompletion : return is not an array"); $isAssoc = is_array ($completeArr) && array_diff_key ($completeArr, array_keys (array_keys ($completeArr))); // Remove from completeArr the proposed values which doesn't match with @@ -334,10 +336,13 @@ class console if (mb_substr ($val, 0, mb_strlen ($end)) !== $end) unset ($completeArr[$key]); } - if (count ($completeArr) === 1) + if (count ($completeArr) === 1 && + ($isAssoc && key ($completeArr) !== "" || + ! $isAssoc && reset ($completeArr) !== "")) { // One entry : add a space to put on the next - $this->debug ("Autocompletion : One entry : add it + ending space"); + $this->debug ("Autocompletion : One entry not empty : ". + "add it + ending space"); if ($isAssoc) $string = $start.key ($completeArr)." "; else