Skip to content

Commit e15d1ff

Browse files
committed
Improve tabs expansion
``` \tx xxxx\tx ``` should render: ``` x xxxx x ```
1 parent 38f6720 commit e15d1ff

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/applications/differential/render/DifferentialChangesetRenderer.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,19 @@ final public function renderChangesetTable($content) {
366366
// TODO: Let the user customize their tab width / display style.
367367
// TODO: We should possibly post-process "\r" as well.
368368
// TODO: Both these steps should happen earlier.
369-
$result = str_replace("\t", ' ', $result);
369+
$result = $this->expandLineTabs($result);
370370

371371
return phutil_safe_html($result);
372372
}
373373

374+
private function expandLineTabs($line, $tab_size = 8) {
375+
while (false !== ($pos = strpos($line, "\t"))) {
376+
$expanded_tab = str_repeat(' ', $tab_size - ($pos % $tab_size));
377+
$line = substr_replace($line, $expanded_tab, $pos, 1);
378+
}
379+
return $line;
380+
}
381+
374382
abstract public function isOneUpRenderer();
375383
abstract public function renderTextChange(
376384
$range_start,

0 commit comments

Comments
 (0)