From 5f459c7eaf9577292dd7bbf4b30164b3f53e79f3 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sun, 12 Apr 2026 20:57:20 +0800 Subject: feat: implement form submission support by tracking input fields and form context during rendering --- src/core/browser.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/core/browser.cc') diff --git a/src/core/browser.cc b/src/core/browser.cc index e3a739a..0f6d9d2 100644 --- a/src/core/browser.cc +++ b/src/core/browser.cc @@ -33,7 +33,7 @@ struct PageData { std::vector lines; std::vector links; - std::vector inputs; + std::vector inputs; std::string title; }; @@ -390,7 +390,7 @@ InputAction handle_form_input( const tui::Terminal& terminal, return InputAction::None; } - std::string target_url; + const auto& target_input = page_data.inputs[index - 1]; std::string encoded_query = query; for ( char& ch : encoded_query ) { if ( ch == ' ' ) { @@ -398,12 +398,21 @@ InputAction handle_form_input( const tui::Terminal& terminal, } } - if ( current_url.contains( "wikipedia.org" ) ) { - target_url = "https://en.wikipedia.org/w/index.php?search=" + encoded_query; + std::string action = target_input.action; + if ( action.empty() ) { + action = current_url; } else { - target_url = "https://lite.duckduckgo.com/lite/?q=" + encoded_query; + action = normalize_url( action, current_url ); } + std::string param_name = target_input.name; + if ( param_name.empty() ) { + param_name = "q"; + } + + const char sep = action.contains( '?' ) ? '&' : '?'; + const std::string target_url = action + sep + param_name + "=" + encoded_query; + history.resize( history_idx + 1 ); history.push_back( target_url ); history_idx++; -- cgit v1.2.3