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:
+23
-2
@@ -16,6 +16,15 @@ fn address_is_valid(addr: &str) -> bool {
|
|||||||
!addr.is_empty() && !addr.contains(':')
|
!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)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum UserIcon {
|
pub enum UserIcon {
|
||||||
Normal,
|
Normal,
|
||||||
@@ -866,7 +875,13 @@ fn AddServerModal(on_save: EventHandler<ServerEntry>, on_cancel: EventHandler<()
|
|||||||
placeholder: "mumble.example.com",
|
placeholder: "mumble.example.com",
|
||||||
pattern: ADDRESS_PATTERN,
|
pattern: ADDRESS_PATTERN,
|
||||||
value: "{address.read()}",
|
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,
|
required: true,
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
@@ -995,7 +1010,13 @@ fn EditServerModal(
|
|||||||
placeholder: "mumble.example.com",
|
placeholder: "mumble.example.com",
|
||||||
pattern: ADDRESS_PATTERN,
|
pattern: ADDRESS_PATTERN,
|
||||||
value: "{address.read()}",
|
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,
|
required: true,
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
|
|||||||
Reference in New Issue
Block a user