Cmd or Ctrl+L should focus on location bar in minibrowser mode (#30105)

* cmd or ctrl+L should focus on location bar

* review fix: rename response to location_field
This commit is contained in:
Atbrakhi 2023-08-18 10:20:53 +02:00 committed by GitHub
parent 1efecf9b50
commit 0e7c958bd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 14 deletions

View file

@ -113,17 +113,19 @@ where
} }
}) })
.shortcut(CMD_OR_CONTROL, 'L', || { .shortcut(CMD_OR_CONTROL, 'L', || {
let url: String = if let Some(ref current_url) = self.current_url { if !opts::get().minibrowser {
current_url.to_string() let url: String = if let Some(ref current_url) = self.current_url {
} else { current_url.to_string()
String::from("") } else {
}; String::from("")
let title = "URL or search query"; };
let input = tinyfiledialogs::input_box(title, title, &tiny_dialog_escape(&url)); let title = "URL or search query";
if let Some(input) = input { let input = tinyfiledialogs::input_box(title, title, &tiny_dialog_escape(&url));
if let Some(url) = sanitize_url(&input) { if let Some(input) = input {
if let Some(id) = self.browser_id { if let Some(url) = sanitize_url(&input) {
self.event_queue.push(EmbedderEvent::LoadUrl(id, url)); if let Some(id) = self.browser_id {
self.event_queue.push(EmbedderEvent::LoadUrl(id, url));
}
} }
} }
} }

View file

@ -4,7 +4,7 @@
use std::{cell::{RefCell, Cell}, sync::Arc}; use std::{cell::{RefCell, Cell}, sync::Arc};
use egui::TopBottomPanel; use egui::{TopBottomPanel, Modifiers, Key};
use servo::{servo_url::ServoUrl, compositing::windowing::EmbedderEvent}; use servo::{servo_url::ServoUrl, compositing::windowing::EmbedderEvent};
use servo::webrender_surfman::WebrenderSurfman; use servo::webrender_surfman::WebrenderSurfman;
@ -55,12 +55,17 @@ impl Minibrowser {
event_queue.borrow_mut().push(MinibrowserEvent::Go); event_queue.borrow_mut().push(MinibrowserEvent::Go);
location_dirty.set(false); location_dirty.set(false);
} }
if ui.add_sized(
let location_field = ui.add_sized(
ui.available_size(), ui.available_size(),
egui::TextEdit::singleline(&mut *location.borrow_mut()), egui::TextEdit::singleline(&mut *location.borrow_mut()),
).changed() { );
if location_field.changed() {
location_dirty.set(true); location_dirty.set(true);
} }
if ui.input(|i| i.clone().consume_key(Modifiers::COMMAND, Key::L)) {
location_field.request_focus();
}
}, },
); );
}); });