gui: split host:port pasted into address field

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-05 06:32:15 +00:00
committed by Sam Sartor
parent 614c7f7d56
commit 32892f8062
+23 -2
View File
@@ -16,6 +16,15 @@ fn address_is_valid(addr: &str) -> bool {
!addr.is_empty() && !addr.contains(':')
}
fn split_host_port(input: &str) -> (String, Option<String>) {
if let Some((host, port)) = input.rsplit_once(':') {
if !port.is_empty() && port.chars().all(|c| c.is_ascii_digit()) {
return (host.to_string(), Some(port.to_string()));
}
}
(input.to_string(), None)
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum UserIcon {
Normal,
@@ -897,7 +906,13 @@ fn AddServerModal(on_save: EventHandler<ServerEntry>, on_cancel: EventHandler<()
placeholder: "mumble.example.com",
pattern: ADDRESS_PATTERN,
value: "{address.read()}",
oninput: move |evt| address.set(evt.value().clone()),
oninput: move |evt| {
let (host, maybe_port) = split_host_port(&evt.value());
address.set(host);
if let Some(p) = maybe_port {
port.set(p);
}
},
required: true,
}
div {
@@ -1025,7 +1040,13 @@ fn EditServerModal(
placeholder: "mumble.example.com",
pattern: ADDRESS_PATTERN,
value: "{address.read()}",
oninput: move |evt| address.set(evt.value().clone()),
oninput: move |evt| {
let (host, maybe_port) = split_host_port(&evt.value());
address.set(host);
if let Some(p) = maybe_port {
port.set(p);
}
},
required: true,
}
div {