Skip to content

Commit

Permalink
Prompt URL on Cmd/Ctrl-L
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Mar 4, 2018
1 parent 76552b3 commit bb04b95
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ports/servo/Cargo.toml
Expand Up @@ -40,6 +40,7 @@ servo_geometry = {path = "../../components/geometry"}
servo_config = {path = "../../components/config"}
servo_url = {path = "../../components/url"}
style_traits = {path = "../../components/style_traits"}
tinyfiledialogs = "3.0"
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}

[target.'cfg(not(target_os = "android"))'.dependencies]
Expand Down
34 changes: 34 additions & 0 deletions ports/servo/glutin_app/window.rs
Expand Up @@ -21,6 +21,7 @@ use glutin::os::macos::{ActivationPolicy, WindowBuilderExt};
use msg::constellation_msg::{self, Key, TopLevelBrowsingContextId as BrowserId};
use msg::constellation_msg::{KeyModifiers, KeyState, TraversalDirection};
use net_traits::net_error_list::NetError;
use net_traits::pub_domains::is_reg_domain;
#[cfg(any(target_os = "linux", target_os = "macos"))]
use osmesa_sys;
use script_traits::{LoadData, TouchEventType};
Expand All @@ -43,6 +44,7 @@ use std::time;
use style_traits::DevicePixel;
use style_traits::cursor::CursorKind;
use super::NestedEventLoopListener;
use tinyfiledialogs;
#[cfg(target_os = "windows")]
use user32;
use webrender_api::{DeviceUintRect, DeviceUintSize, ScrollLocation};
Expand Down Expand Up @@ -1321,6 +1323,21 @@ impl WindowMethods for Window {
self.event_queue.borrow_mut().push(WindowEvent::Reload(browser_id));
}
}
(CMD_OR_CONTROL, Some('l'), _) => {
if let Some(true) = PREFS.get("shell.builtin-key-shortcuts.enabled").as_boolean() {
let url: String = if let Some(ref url) = *self.current_url.borrow() {
url.to_string()
} else {
String::from("")
};
let title = "URL or search query";
if let Some(input) = tinyfiledialogs::input_box(title, title, &url) {
if let Some(url) = sanitize_url(&input) {
self.event_queue.borrow_mut().push(WindowEvent::LoadUrl(browser_id, url));
}
}
}
}
(CMD_OR_CONTROL, Some('q'), _) => {
if let Some(true) = PREFS.get("shell.builtin-key-shortcuts.enabled").as_boolean() {
self.event_queue.borrow_mut().push(WindowEvent::Quit);
Expand Down Expand Up @@ -1448,3 +1465,20 @@ fn filter_nonprintable(ch: char, key_code: VirtualKeyCode) -> Option<char> {
None
}
}

fn sanitize_url(request: &str) -> Option<ServoUrl> {
let request = request.trim();
ServoUrl::parse(&request).ok()
.or_else(|| {
if request.contains('/') || is_reg_domain(request) {
ServoUrl::parse(&format!("http://{}", request)).ok()
} else {
None
}
}).or_else(|| {
PREFS.get("shell.searchpage").as_string().and_then(|s: &str| {
let url = s.replace("%s", request);
ServoUrl::parse(&url).ok()
})
})
}
1 change: 1 addition & 0 deletions ports/servo/main.rs
Expand Up @@ -40,6 +40,7 @@ extern crate servo_url;
#[macro_use]
extern crate sig;
extern crate style_traits;
extern crate tinyfiledialogs;
extern crate webrender_api;
#[cfg(target_os = "windows")] extern crate winapi;
#[cfg(target_os = "windows")] extern crate user32;
Expand Down
1 change: 1 addition & 0 deletions resources/prefs.json
Expand Up @@ -68,5 +68,6 @@
"shell.keep_screen_on.enabled": false,
"shell.native-orientation": "both",
"shell.native-titlebar.enabled": true,
"shell.searchpage": "https://duckduckgo.com/html/?q=%s",
"webgl.testing.context_creation_error": false
}

0 comments on commit bb04b95

Please sign in to comment.