aboutsummaryrefslogtreecommitdiff
path: root/src/core/browser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/browser.cc')
-rw-r--r--src/core/browser.cc19
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++;