From c01030a636ed989a4d9d03cdc788a497f308bd38 Mon Sep 17 00:00:00 2001 From: Sam Sartor Date: Tue, 5 May 2026 06:32:15 +0000 Subject: [PATCH] gui: split host:port pasted into address field Co-Authored-By: Claude Opus 4.7 (1M context) --- gui/src/main.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/gui/src/main.rs b/gui/src/main.rs index 0571fae..f2e8ddf 100644 --- a/gui/src/main.rs +++ b/gui/src/main.rs @@ -16,6 +16,15 @@ fn address_is_valid(addr: &str) -> bool { !addr.is_empty() && !addr.contains(':') } +fn split_host_port(input: &str) -> (String, Option) { + 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, @@ -866,7 +875,13 @@ fn AddServerModal(on_save: EventHandler, 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 { @@ -995,7 +1010,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 {