mcview: make backward search interruptible.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2016-04-29 14:52:33 +03:00
parent c13e4b3c0e
commit 3af54b0e93

View File

@ -115,6 +115,10 @@ mcview_search_update_steps (WView * view)
/* Do not update the percent display but every 20 kb */
if (view->update_steps < 20000)
view->update_steps = 20000;
/* Make interrupt more responsive */
if (view->update_steps > 40000)
view->update_steps = 40000;
}
/* --------------------------------------------------------------------------------------------- */
@ -132,6 +136,8 @@ mcview_find (mcview_search_status_msg_t * ssm, off_t search_start, off_t search_
search_end = mcview_get_filesize (view);
while (search_start >= 0)
{
gboolean ok;
view->search_nroff_seq->index = search_start;
mcview_nroff_seq_info (view->search_nroff_seq);
@ -139,14 +145,18 @@ mcview_find (mcview_search_status_msg_t * ssm, off_t search_start, off_t search_
&& mc_search_is_fixed_search_str (view->search))
search_end = search_start + view->search->original_len;
if (mc_search_run (view->search, (void *) ssm, search_start, search_end, len)
&& view->search->normal_offset == search_start)
ok = mc_search_run (view->search, (void *) ssm, search_start, search_end, len);
if (ok && view->search->normal_offset == search_start)
{
if (view->text_nroff_mode)
view->search->normal_offset++;
return TRUE;
}
/* Abort search. */
if (!ok && view->search->error == MC_SEARCH_E_ABORT)
return FALSE;
search_start--;
}
@ -247,16 +257,33 @@ mcview_search_update_cmd_callback (const void *user_data, gsize char_offset)
{
status_msg_t *sm = STATUS_MSG (user_data);
mcview_search_status_msg_t *vsm = (mcview_search_status_msg_t *) user_data;
WView *view = vsm->view;
gboolean do_update = FALSE;
mc_search_cbret_t result = MC_SEARCH_CB_OK;
vsm->offset = (off_t) char_offset;
if (vsm->offset >= vsm->view->update_activate)
{
vsm->view->update_activate += vsm->view->update_steps;
if (sm->update (sm) == B_CANCEL)
result = MC_SEARCH_CB_ABORT;
if (mcview_search_options.backwards)
{
if (vsm->offset <= view->update_activate)
{
view->update_activate -= view->update_steps;
do_update = TRUE;
}
}
else
{
if (vsm->offset >= view->update_activate)
{
view->update_activate += view->update_steps;
do_update = TRUE;
}
}
if (do_update && sm->update (sm) == B_CANCEL)
result = MC_SEARCH_CB_ABORT;
/* may be in future return from this callback will change current position in searching block. */