diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-04-12 20:57:20 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-04-12 20:57:20 +0800 |
| commit | 5f459c7eaf9577292dd7bbf4b30164b3f53e79f3 (patch) | |
| tree | 5f213c704a6f348ebe584d4bfbdca8313b6fd8c4 /src/core | |
| parent | 32bce7c278e8f52d96579650088f610d62920f00 (diff) | |
| download | rwebbrowser-5f459c7eaf9577292dd7bbf4b30164b3f53e79f3.tar.gz rwebbrowser-5f459c7eaf9577292dd7bbf4b30164b3f53e79f3.tar.xz | |
feat: implement form submission support by tracking input fields and form context during rendering
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/browser.cc | 19 |
1 files changed, 14 insertions, 5 deletions
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<std::string> lines; std::vector<std::string> links; - std::vector<std::string> inputs; + std::vector<render::InputField> 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++; |
