Skip to content

Commit

Permalink
fix(documentator): Markdown Editor:mutate() will rtrim all changed …
Browse files Browse the repository at this point in the history
…lines to avoid whitespaces at the end of the line.
  • Loading branch information
LastDragon-ru committed Aug 29, 2024
1 parent 73897b7 commit 571c1a1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/documentator/src/Markdown/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use function count;
use function implode;
use function mb_substr;
use function rtrim;
use function usort;

use const PHP_INT_MAX;
Expand Down Expand Up @@ -106,17 +107,17 @@ public function mutate(iterable $changes): static {

for ($t = 0; $t < $count; $t++) {
$insert[] = match (true) {
$t === 0 => $prefix.$text[$t],
$t === $count - 1 => $padding.$text[$t].$suffix,
default => $padding.$text[$t],
$t === 0 => rtrim($prefix.$text[$t]),
$t === $count - 1 => rtrim($padding.$text[$t].$suffix),
default => rtrim($padding.$text[$t]),
};
}

array_splice($lines, $number, 1, $insert);
} elseif ($count === 1) {
$lines[$number] = $prefix.$text[0].$suffix;
$lines[$number] = rtrim($prefix.$text[0].$suffix);
} elseif (($prefix && $prefix !== $padding) || $suffix) {
$lines[$number] = $prefix.$suffix;
$lines[$number] = rtrim($prefix.$suffix);
} else {
unset($lines[$number]);
}
Expand Down

0 comments on commit 571c1a1

Please sign in to comment.