|
54 | 54 | using namespace lnav::roles::literals; |
55 | 55 |
|
56 | 56 | filter_sub_source::filter_sub_source(std::shared_ptr<textinput_curses> editor) |
57 | | - : fss_editor(std::move(editor)), |
58 | | - fss_regexp_history( |
59 | | - lnav::textinput::history::for_context("regexp-filter"_frag)), |
60 | | - fss_sql_history(lnav::textinput::history::for_context("sql-filter"_frag)) |
| 57 | + : fss_editor(std::move(editor)) |
61 | 58 | { |
| 59 | + static auto& prompt = lnav::prompt::get(); |
| 60 | + |
62 | 61 | this->fss_editor->set_visible(false); |
63 | 62 | this->fss_editor->set_x(28); |
64 | 63 | this->fss_editor->tc_popup.set_title("Pattern"); |
65 | 64 | this->fss_editor->tc_height = 1; |
66 | 65 | this->fss_editor->tc_on_change |
67 | 66 | = bind_mem(&filter_sub_source::rl_change, this); |
68 | 67 | this->fss_editor->tc_on_history_search |
69 | | - = bind_mem(&filter_sub_source::rl_history, this); |
| 68 | + = bind_mem(&lnav::prompt::rl_history_search, &prompt); |
70 | 69 | this->fss_editor->tc_on_history_list |
71 | | - = bind_mem(&filter_sub_source::rl_history, this); |
| 70 | + = bind_mem(&lnav::prompt::rl_history_list, &prompt); |
72 | 71 | this->fss_editor->tc_on_completion_request |
73 | 72 | = bind_mem(&filter_sub_source::rl_completion_request, this); |
74 | 73 | this->fss_editor->tc_on_completion |
75 | | - = bind_mem(&filter_sub_source::rl_completion, this); |
| 74 | + = bind_mem(&lnav::prompt::rl_completion, &prompt); |
76 | 75 | this->fss_editor->tc_on_perform |
77 | 76 | = bind_mem(&filter_sub_source::rl_perform, this); |
78 | 77 | this->fss_editor->tc_on_blur = bind_mem(&filter_sub_source::rl_blur, this); |
@@ -433,42 +432,22 @@ filter_sub_source::text_size_for_line(textview_curses& tc, |
433 | 432 | void |
434 | 433 | filter_sub_source::rl_change(textinput_curses& rc) |
435 | 434 | { |
| 435 | + static auto& prompt = lnav::prompt::get(); |
| 436 | + |
| 437 | + if (rc.tc_popup_type == textinput_curses::popup_type_t::history |
| 438 | + && !prompt.p_replace_from_history) |
| 439 | + { |
| 440 | + rc.tc_on_history_search(rc); |
| 441 | + return; |
| 442 | + } |
| 443 | + |
436 | 444 | auto* top_view = *lnav_data.ld_view_stack.top(); |
437 | 445 | auto rows = this->rows_for(top_view); |
438 | 446 | auto& row = rows[this->tss_view->get_selection().value()]; |
439 | 447 |
|
440 | 448 | row->ti_change(top_view, rc); |
441 | 449 | } |
442 | 450 |
|
443 | | -void |
444 | | -filter_sub_source::rl_history(textinput_curses& tc) |
445 | | -{ |
446 | | - switch (tc.tc_text_format) { |
447 | | - case text_format_t::TF_PCRE: { |
448 | | - std::vector<attr_line_t> poss; |
449 | | - this->fss_regexp_history.query_entries( |
450 | | - tc.get_content(), [&poss, &tc](const auto& e) { |
451 | | - auto al |
452 | | - = attr_line_t::from_table_cell_content(e.e_content, |
453 | | - tc.get_width()) |
454 | | - .highlight_fuzzy_matches(tc.get_content()) |
455 | | - .with_attr_for_all( |
456 | | - lnav::prompt::SUBST_TEXT.value(e.e_content)); |
457 | | - poss.emplace_back(al); |
458 | | - }); |
459 | | - tc.open_popup_for_history(poss); |
460 | | - break; |
461 | | - } |
462 | | - case text_format_t::TF_PLAINTEXT: |
463 | | - case text_format_t::TF_SQL: { |
464 | | - break; |
465 | | - } |
466 | | - default: |
467 | | - ensure(false); |
468 | | - break; |
469 | | - } |
470 | | -} |
471 | | - |
472 | 451 | void |
473 | 452 | filter_sub_source::rl_completion_request_int(textinput_curses& tc, |
474 | 453 | completion_request_type_t crt) |
@@ -1014,6 +993,10 @@ filter_sub_source::text_filter_row::prime_text_input(textview_curses* top_view, |
1014 | 993 | { |
1015 | 994 | static auto& prompt = lnav::prompt::get(); |
1016 | 995 |
|
| 996 | + auto context = this->tfr_filter->get_lang() == filter_lang_t::SQL |
| 997 | + ? lnav::prompt::context_t::sql_filter |
| 998 | + : lnav::prompt::context_t::regex_filter; |
| 999 | + prompt.focus_for(*top_view, ti, context, '\0', {}); |
1017 | 1000 | ti.tc_text_format = this->tfr_filter->get_lang() == filter_lang_t::SQL |
1018 | 1001 | ? text_format_t::TF_SQL |
1019 | 1002 | : text_format_t::TF_PCRE; |
@@ -1210,6 +1193,7 @@ filter_sub_source::text_filter_row::ti_perform(textview_curses* top_view, |
1210 | 1193 | filter_sub_source& parent) |
1211 | 1194 | { |
1212 | 1195 | static const intern_string_t INPUT_SRC = intern_string::lookup("input"); |
| 1196 | + static auto& prompt = lnav::prompt::get(); |
1213 | 1197 |
|
1214 | 1198 | auto* tss = top_view->get_sub_source(); |
1215 | 1199 | auto& fs = tss->get_filters(); |
@@ -1249,7 +1233,7 @@ filter_sub_source::text_filter_row::ti_perform(textview_curses* top_view, |
1249 | 1233 | this->tfr_filter->get_index(), |
1250 | 1234 | code_ptr); |
1251 | 1235 |
|
1252 | | - parent.fss_regexp_history.insert_plain_content(new_value); |
| 1236 | + prompt.get_history_for().insert_plain_content(new_value); |
1253 | 1237 |
|
1254 | 1238 | auto iter |
1255 | 1239 | = std::find(fs.begin(), fs.end(), this->tfr_filter); |
@@ -1289,6 +1273,7 @@ filter_sub_source::text_filter_row::ti_perform(textview_curses* top_view, |
1289 | 1273 | lnav_data.ld_exec_context.ec_msg_callback_stack.back()(um); |
1290 | 1274 | this->ti_abort(top_view, ti, parent); |
1291 | 1275 | } else { |
| 1276 | + prompt.get_history_for().insert_plain_content(new_value); |
1292 | 1277 | lnav_data.ld_log_source.set_sql_filter(new_value, |
1293 | 1278 | stmt.release()); |
1294 | 1279 | tss->text_filters_changed(); |
|
0 commit comments