try autocomplete scheme if the request match local filename

This commit is contained in:
yggverse 2025-02-15 14:44:28 +02:00
parent 9fe6713bc8
commit be9e55a4cf
3 changed files with 38 additions and 30 deletions

View file

@ -129,7 +129,7 @@ impl Window {
action.open.on_activate({
let tab = tab.clone();
move |position, request| {
tab.open(position, &request, true);
tab.open(position, request, true);
}
});

View file

@ -54,7 +54,7 @@ impl Open {
// Actions
/// Formatted action connector for external implementation
pub fn on_activate(&self, callback: impl Fn(Option<i32>, String) + 'static) -> SignalHandlerId {
pub fn on_activate(&self, callback: impl Fn(Option<i32>, &str) + 'static) -> SignalHandlerId {
use gtk::{prelude::FileExt, FileDialog, Window};
use std::rc::Rc;
@ -80,7 +80,7 @@ impl Open {
} else {
Some(state)
},
format!("file://{}", file.path().unwrap().to_str().unwrap()),
file.path().unwrap().to_str().unwrap(),
)
}
}

View file

@ -57,6 +57,13 @@ impl Client {
snap_history(&self.page, None);
}
// try autocomplete scheme if the request match local filename
if std::path::Path::new(&request).exists() {
self.page
.item_action
.load
.activate(Some(&format!("file://{request}")), is_snap_history)
} else {
// run async resolver to detect Uri, scheme-less host, or search query
lookup(&self.profile, request, self.cancellable(), {
let driver = self.driver.clone();
@ -86,6 +93,7 @@ impl Client {
}
})
}
}
/// Get new [Cancellable](https://docs.gtk.org/gio/class.Cancellable.html) by cancel previous one
fn cancellable(&self) -> Cancellable {