1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Hold down a modifier key when clicking a link to open it in a new tab

This commit is contained in:
Emil Ernerfeldt
2021-03-08 17:48:23 +01:00
parent c1ef81628b
commit 1c06622dbc
8 changed files with 69 additions and 15 deletions

View File

@@ -237,8 +237,8 @@ pub fn handle_output(output: &egui::Output) {
} = output;
set_cursor_icon(*cursor_icon);
if let Some(url) = open_url {
crate::open_url(url);
if let Some(open) = open_url {
crate::open_url(&open.url, open.new_tab);
}
#[cfg(web_sys_unstable_apis)]
@@ -299,9 +299,11 @@ fn cursor_web_name(cursor: egui::CursorIcon) -> &'static str {
}
}
pub fn open_url(url: &str) -> Option<()> {
pub fn open_url(url: &str, new_tab: bool) -> Option<()> {
let name = if new_tab { "_blank" } else { "_self" };
web_sys::window()?
.open_with_url_and_target(url, "_self")
.open_with_url_and_target(url, name)
.ok()?;
Some(())
}