Fixed finds twice in backward direction in nroff'ed text

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2011-07-17 16:11:53 +03:00
parent 7af542b76e
commit b3e9a75e72
3 changed files with 73 additions and 3 deletions

View File

@ -315,6 +315,8 @@ mcview_nroff_t *mcview_nroff_seq_new (mcview_t * view);
void mcview_nroff_seq_free (mcview_nroff_t **);
nroff_type_t mcview_nroff_seq_info (mcview_nroff_t *);
int mcview_nroff_seq_next (mcview_nroff_t *);
int mcview_nroff_seq_prev (mcview_nroff_t *);
/* plain.c: */
void mcview_display_text (mcview_t *);

View File

@ -403,3 +403,56 @@ mcview_nroff_seq_next (mcview_nroff_t * nroff)
}
/* --------------------------------------------------------------------------------------------- */
int
mcview_nroff_seq_prev (mcview_nroff_t * nroff)
{
int prev;
off_t prev_index, prev_index2;
if (nroff == NULL)
return -1;
nroff->prev_type = NROFF_TYPE_NONE;
if (nroff->index == 0)
return -1;
prev_index = nroff->index - 1;
while (prev_index != 0)
{
if (mcview_nroff_get_char (nroff, &nroff->current_char, prev_index))
break;
prev_index--;
}
if (prev_index == 0)
{
nroff->index--;
mcview_nroff_seq_info (nroff);
return nroff->current_char;
}
prev_index--;
if (!mcview_get_byte (nroff->view, prev_index, &prev) || prev != '\b')
{
nroff->index = prev_index;
mcview_nroff_seq_info (nroff);
return nroff->current_char;
}
prev_index2 = prev_index - 1;
while (prev_index2 != 0)
{
if (mcview_nroff_get_char (nroff, &prev, prev_index))
break;
prev_index2--;
}
nroff->index = (prev_index2 == 0) ? prev_index : prev_index2;
mcview_nroff_seq_info (nroff);
return nroff->current_char;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -266,9 +266,24 @@ mcview_do_search (mcview_t * view)
search_start = view->search_start + (mcview_search_options.backwards ? -2 : 0);
else
{
int nroff_real_len = mcview__get_nroff_real_len (view, view->search_start + 1, 2);
search_start = mcview_search_options.backwards ? -2 : nroff_real_len != 0 ? 1 : 0;
search_start += view->search_start + nroff_real_len * search_start;
if (mcview_search_options.backwards)
{
mcview_nroff_t *nroff;
nroff = mcview_nroff_seq_new_num (view, view->search_start);
if (mcview_nroff_seq_prev (nroff) != -1)
search_start =
-(mcview__get_nroff_real_len (view, nroff->index - 1, 2) +
nroff->char_width + 1);
else
search_start = -2;
mcview_nroff_seq_free (&nroff);
}
else
{
search_start = mcview__get_nroff_real_len (view, view->search_start + 1, 2);
}
search_start += view->search_start;
}
}