File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -283,7 +283,17 @@ protected function moveSelectionVertically(string $direction) : void
283
283
{
284
284
$ itemKeys = array_keys ($ this ->items );
285
285
286
+ $ increments = 0 ;
287
+
286
288
do {
289
+ $ increments ++;
290
+
291
+ if ($ increments > count ($ itemKeys )) {
292
+ //full cycle detected, there must be no selected items
293
+ //in the menu, so stop trying to select one.
294
+ return ;
295
+ }
296
+
287
297
$ direction === 'UP '
288
298
? $ this ->selectedItem --
289
299
: $ this ->selectedItem ++;
Original file line number Diff line number Diff line change @@ -920,6 +920,20 @@ public function testGetSelectedItemThrowsExceptionIfNoSelectedItem() : void
920
920
$ menu ->getSelectedItem ();
921
921
}
922
922
923
+ public function testMenuCanOpenAndFunctionWithoutAnySelectableItems () : void
924
+ {
925
+ $ this ->terminal ->expects ($ this ->exactly (3 ))
926
+ ->method ('read ' )
927
+ ->willReturn ("\033[B " , "\033[B " , 'Q ' );
928
+ $ menu = new CliMenu ('PHP School FTW ' , [new StaticItem ('One ' )], $ this ->terminal );
929
+ $ menu ->addCustomControlMapping ('Q ' , function (CliMenu $ menu ) {
930
+ $ menu ->close ();
931
+ });
932
+ $ menu ->open ();
933
+
934
+ self ::assertCount (1 , $ menu ->getItems ());
935
+ }
936
+
923
937
private function getTestFile () : string
924
938
{
925
939
return sprintf ('%s/res/%s.txt ' , __DIR__ , $ this ->getName ());
You can’t perform that action at this time.
0 commit comments