From cdf3dbcf046a2691455f8c2a86763a5e6f900b81 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 25 Sep 2024 02:35:54 +0300 Subject: [PATCH] implement page reload on request auto-routed --- src/browser/main/tab/page/mod.rs | 16 +++++++++++----- src/browser/main/tab/page/navigation/mod.rs | 5 +++++ .../main/tab/page/navigation/request/mod.rs | 9 +++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/browser/main/tab/page/mod.rs b/src/browser/main/tab/page/mod.rs index c4687235..171bc7f9 100644 --- a/src/browser/main/tab/page/mod.rs +++ b/src/browser/main/tab/page/mod.rs @@ -49,19 +49,25 @@ impl Page { println!("Parsed URI: {}", uri); // @TODO } Err(_) => { - // Request contain host substring + // Try interpret host manually if Regex::match_simple( r"regex(^[^\/\s]+\.[\w]{2,})regex", request_text.clone(), RegexCompileFlags::DEFAULT, RegexMatchFlags::DEFAULT, ) { - let request_text = format!("gemini://{request_text}"); - // @TODO reload + // Seems request contain some host substring + self.navigation.set_request_text( + &GString::from(format!("gemini://{request_text}")), + true, // activate (page reload) @TODO validate new uri instead? + ); } else { + // Plain text given, make search request to default provider Uri::escape_string(&request_text, None, false); - let request_text = format!("gemini://tlgs.one/search?{request_text}"); - // @TODO reload + self.navigation.set_request_text( + &GString::from(format!("gemini://tlgs.one/search?{request_text}")), + true, // activate (page reload) + ); } } }; diff --git a/src/browser/main/tab/page/navigation/mod.rs b/src/browser/main/tab/page/navigation/mod.rs index 4e41508c..5869f0be 100644 --- a/src/browser/main/tab/page/navigation/mod.rs +++ b/src/browser/main/tab/page/navigation/mod.rs @@ -68,6 +68,11 @@ impl Navigation { self.bookmark.update(); } + // Setters + pub fn set_request_text(&self, value: &GString, activate: bool) { + self.request.set_text(value, activate); + } + // Getters pub fn widget(&self) -> &Box { &self.widget diff --git a/src/browser/main/tab/page/navigation/request/mod.rs b/src/browser/main/tab/page/navigation/request/mod.rs index 15e0538a..42b34f5d 100644 --- a/src/browser/main/tab/page/navigation/request/mod.rs +++ b/src/browser/main/tab/page/navigation/request/mod.rs @@ -37,6 +37,15 @@ impl Request { // @TODO animate progress fraction } + // Setters + pub fn set_text(&self, value: &GString, activate: bool) { + self.widget.set_text(value); + + if activate { + self.widget.activate(); + } + } + // Getters pub fn widget(&self) -> &Entry { &self.widget