diff --git a/src/Concerns/TypedValue.php b/src/Concerns/TypedValue.php index 52c40f24..33ff0c56 100644 --- a/src/Concerns/TypedValue.php +++ b/src/Concerns/TypedValue.php @@ -96,12 +96,12 @@ protected function addCursor(string $value, int $cursorPosition, int $maxWidth): $cursor = mb_strlen($current) && $current !== PHP_EOL ? $current : ' '; - $spaceBefore = $maxWidth - mb_strwidth($cursor) - (mb_strwidth($after) > 0 ? 1 : 0); + $spaceBefore = $maxWidth < 0 ? mb_strwidth($before) : $maxWidth - mb_strwidth($cursor) - (mb_strwidth($after) > 0 ? 1 : 0); [$truncatedBefore, $wasTruncatedBefore] = mb_strwidth($before) > $spaceBefore ? [$this->trimWidthBackwards($before, 0, $spaceBefore - 1), true] : [$before, false]; - $spaceAfter = $maxWidth - ($wasTruncatedBefore ? 1 : 0) - mb_strwidth($truncatedBefore) - mb_strwidth($cursor); + $spaceAfter = $maxWidth < 0 ? mb_strwidth($after) : $maxWidth - ($wasTruncatedBefore ? 1 : 0) - mb_strwidth($truncatedBefore) - mb_strwidth($cursor); [$truncatedAfter, $wasTruncatedAfter] = mb_strwidth($after) > $spaceAfter ? [mb_strimwidth($after, 0, $spaceAfter - 1), true] : [$after, false]; diff --git a/src/TextareaPrompt.php b/src/TextareaPrompt.php index a3904919..9225f895 100644 --- a/src/TextareaPrompt.php +++ b/src/TextareaPrompt.php @@ -202,7 +202,6 @@ public function valueWithCursor(int $maxWidth): string return $this->dim($this->addCursor($this->placeholder, 0, 10_000)); } - // TODO: Deal with max width properly, 10_000 is a hack - return $this->addCursor($value, $this->cursorPosition, 10_000); + return $this->addCursor($value, $this->cursorPosition, -1); } }