lib/PublicInbox/SearchView.pm | 18 ++++++++++++++---- lib/PublicInbox/View.pm | 57 ++++++++++++++++++++++++++++++++--------------------- diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index ab3dddb48252ea62197fd79d8fbb2d746175825b..5d4f4fe249c38157318d8fc50b0cbc132ad567ac 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -138,7 +138,7 @@ sub tdump { my ($cb, $res, $mset, $q, $ctx) = @_; my $fh = $cb->([200, ['Content-Type'=>'text/html; charset=UTF-8']]); - $fh->write($res); + $fh->write($res .= ''); my %pct; my @m = map { my $i = $_; @@ -168,9 +168,15 @@ $th->order(*PublicInbox::View::rsort_ts); } my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir}); - my $state = { ctx => $ctx, anchor_idx => 0, pct => \%pct }; + my $state = { + ctx => $ctx, + anchor_idx => 0, + pct => \%pct, + cur_level => 0 + }; $ctx->{searchview} = 1; tdump_ent($fh, $git, $state, $_, 0) for $th->rootset; + PublicInbox::View::thread_adj_level($fh, $state, 0); Email::Address->purge_cache; $fh->write(search_nav_bot($mset, $q). "\n\n" . @@ -193,10 +199,13 @@ Email::MIME->new($git->cat_file('HEAD:'.$path)); }; } if ($mime) { + my $end = + PublicInbox::View::thread_adj_level($fh, $state, $level); PublicInbox::View::index_entry($fh, $mime, $level, $state); + $fh->write($end) if $end; } else { my $mid = $node->messageid; - $fh->write(PublicInbox::View::ghost_table('', $mid, $level)); + PublicInbox::View::ghost_flush($fh, $state, '', $mid, $level); } tdump_ent($fh, $git, $state, $node->child, $level + 1); tdump_ent($fh, $git, $state, $node->next, $level); @@ -214,7 +223,8 @@ my $query = PublicInbox::Hval->new_oneline($q->{q}); my $qh = $query->as_html; my $A = $q->qs_html(x => 'A', r => undef); - my $res = "$qh - search results" . + my $res = '' . PublicInbox::Hval::STYLE . + "$qh - search results" . qq{! . qq{} . diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 204004709474d914e6cca17adc09e3e0f74f70cb..fac0fcb161cc9ec95cd2512ac0ec2219c61d633d 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -176,7 +176,7 @@ ctx => $ctx, seen => $seen, root_anchor => anchor_for($mid), anchor_idx => 0, - max_level => 0, + cur_level => 0, }; require PublicInbox::Git; @@ -187,9 +187,8 @@ __thread_entry(\$cb, $git, $state, $_, 0) for (@$msgs); } else { my $th = thread_results($msgs); thread_entry(\$cb, $git, $state, $_, 0) for $th->rootset; - if (my $max = $state->{max_level}) { - my $x = $max > 1 ? ('' x ($max-1)) : ''; - $cb->write($x . ''); + if (my $max = $state->{cur_level}) { + $cb->write(('' x ($max - 1)) . ''); } } $git = undef; @@ -638,25 +637,37 @@ my $html = $mid->as_html; qq{[parent not found: <$html>]}; } -sub __thread_adj_level { - my ($cb, $state, $level) = @_; +sub thread_adj_level { + my ($fh, $state, $level) = @_; + + my $max = $state->{cur_level}; + if ($level <= 0) { + return '' if $max == 0; # flat output - return if $level <= 0; # flat output - my $max = $state->{max_level}; - if ($level > $max) { - $state->{max_level} = $level; - $$cb->write(($max ? '
  • ' : ''). '
    • '); - } else { - $$cb->write('
    • '); + # reset existing lists + my $x = $max > 1 ? ('
  • ' x ($max - 1)) : ''; + $fh->write($x . ''); + $state->{cur_level} = 0; + return ''; } + if ($level == $max) { # continue existing list + $fh->write('
  • '); + } elsif ($level < $max) { + my $x = $max > 1 ? ('
  • ' x ($max - $level)) : ''; + $fh->write($x .= '
  • '); + $state->{cur_level} = $level; + } else { # ($level > $max) # start a new level + $state->{cur_level} = $level; + $fh->write(($max ? '
  • ' : '') . '
    • '); + } + '
    • '; } -sub __ghost_flush { - my ($cb, $state, $upfx, $mid, $level) = @_; +sub ghost_flush { + my ($fh, $state, $upfx, $mid, $level) = @_; - __thread_adj_level($cb, $state, $level); - $$cb->write('
      '. ghost_parent($upfx, $mid) .  '
      ' . - ($level > 0 ? '' : '')); + my $end = thread_adj_level($fh, $state, $level); + $fh->write('
      '. ghost_parent($upfx, $mid) .  '
      ' . $end); } sub __thread_entry { @@ -671,16 +682,16 @@ if ($state->{anchor_idx} == 0) { thread_html_head($cb, $mime, $state, $level); } - + my $fh = $$cb; if (my $ghost = delete $state->{ghost}) { # n.b. ghost messages may only be parents, not children foreach my $g (@$ghost) { - __ghost_flush($cb, $state, '../../', @$g); + ghost_flush($fh, $state, '../../', @$g); } } - __thread_adj_level($cb, $state, $level); - index_entry($$cb, $mime, $level, $state); - $$cb->write('') if $level > 0; + my $end = thread_adj_level($fh, $state, $level); + index_entry($fh, $mime, $level, $state); + $fh->write($end) if $end; 1; }