Skip to content

Commit b079c5e

Browse files
authored
fix(console): properly place cursor in multiline input (#1141)
1 parent 797392e commit b079c5e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Tempest/Console/src/Components/Renderers/TextInputRenderer.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public function render(
4343
$lines = str($buffer->text ?: ($placeholder ?: ''))
4444
->explode("\n")
4545
->flatMap(fn (string $line) => str($line)->chunk($this->maxLineCharacters)->toArray())
46-
->map(static fn (string $line) => str($line)->replaceEnd("\n", ' '))
47-
->filter(fn (ImmutableString $line) => $line->isNotEmpty());
46+
->map(static fn (string $line) => str($line)->replaceEnd("\n", ' '));
4847

4948
// calculates scroll offset based on cursor position
5049
$this->scrollOffset = $this->calculateScrollOffset($lines, $this->maximumLines, $buffer->getRelativeCursorPosition($this->maxLineCharacters)->y);
@@ -53,7 +52,10 @@ public function render(
5352
$displayLines = $lines->slice($this->scrollOffset, $this->state->isFinished() ? 1 : $this->maximumLines);
5453

5554
// if there is nothing to display after the component is done, show "no input"
56-
if ($this->state->isFinished() && $lines->isEmpty()) {
55+
// TODO(innocenzi): clean up
56+
if ($this->state->isFinished() && $lines->filter(fn (ImmutableString $line) => $line->trim()->isNotEmpty())->isEmpty()) {
57+
$displayLines = $displayLines->filter(fn (ImmutableString $line) => $line->trim()->isNotEmpty());
58+
5759
$this->line($this->style('italic dim', 'No input.'))->newLine();
5860
}
5961

0 commit comments

Comments
 (0)