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,6 +113,7 @@ where
} }
}) })
.shortcut(CMD_OR_CONTROL, 'L', || { .shortcut(CMD_OR_CONTROL, 'L', || {
if !opts::get().minibrowser {
let url: String = if let Some(ref current_url) = self.current_url { let url: String = if let Some(ref current_url) = self.current_url {
current_url.to_string() current_url.to_string()
} else { } else {
@ -127,6 +128,7 @@ where
} }
} }
} }
}
}) })
.shortcut(CMD_OR_CONTROL, 'Q', || { .shortcut(CMD_OR_CONTROL, 'Q', || {
self.event_queue.push(EmbedderEvent::Quit); self.event_queue.push(EmbedderEvent::Quit);

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();
}
}, },
); );
}); });