From 14f1d7f0cfcaea3a1f4b9dd36ad1dac40ab3fca3 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Wed, 28 Feb 2024 12:38:39 +0100 Subject: [PATCH] Bugfix history cursor position * Added check to make sure that the cursor does not remain past the end of the line when scrolling to a shorter entry. --- src/Shell.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Shell.php b/src/Shell.php index 82161f5..197184f 100644 --- a/src/Shell.php +++ b/src/Shell.php @@ -118,6 +118,7 @@ class Shell implements WritableStreamInterface, EventEmitterInterface $this->historyIndex++; $this->buffer = $this->history[$this->historyIndex]; } + $this->cursorPos = min(strlen($this->buffer), $this->cursorPos) - $this->scrollOffset; break; case "\e[B": // down if ($this->historyIndex === null) { @@ -130,6 +131,7 @@ class Shell implements WritableStreamInterface, EventEmitterInterface $this->historyIndex--; $this->buffer = $this->history[$this->historyIndex]; } + $this->cursorPos = min(strlen($this->buffer), $this->cursorPos) - $this->scrollOffset; break; case "\e[H": // home