Skip to content

Commit 0c2b183

Browse files
committed
Reset current history position on enter
1 parent 85e861d commit 0c2b183

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Readline.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,10 @@ public function deleteChar($n)
588588
*/
589589
protected function processLine()
590590
{
591+
// reset history cycle position
592+
$this->historyPosition = null;
593+
$this->historyUnsaved = null;
594+
591595
// store and reset/clear/redraw current input
592596
$line = $this->linebuffer;
593597
if ($line !== '') {

tests/ReadlineTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,20 @@ public function testHistoryUpBeyondTopCyclesToFirst()
678678
$this->assertEquals('a', $this->readline->getInput());
679679
}
680680

681+
public function testHistoryUpAndThenEnterRestoresCycleToBottom()
682+
{
683+
$this->readline->addHistory('a');
684+
$this->readline->addHistory('b');
685+
686+
$this->readline->onKeyUp();
687+
688+
$this->readline->onKeyEnter();
689+
690+
$this->readline->onKeyUp();
691+
692+
$this->assertEquals('b', $this->readline->getInput());
693+
}
694+
681695
public function testHistoryDownNotCyclingDoesNotChangeInput()
682696
{
683697
$this->readline->onKeyDown();

0 commit comments

Comments
 (0)