diff --git a/gpui-app/src/ui/connection_form.rs b/gpui-app/src/ui/connection_form.rs index a4e64b0..9b2d298 100644 --- a/gpui-app/src/ui/connection_form.rs +++ b/gpui-app/src/ui/connection_form.rs @@ -253,10 +253,17 @@ impl ConnectionForm { if last_transport.get() == idx { return; } + // 端口只在仍是某个默认端口(而非用户自定义值)时才跟随切换: + // 否则 WSS:9443 → TCP → WSS 的往返会把 9443 静默丢失 + let current = port_for_sub.read(cx).value().trim().parse::().ok(); + let is_default = matches!(current, Some(p) if + TransportKind::ALL.iter().any(|k| k.default_port() == p)); last_transport.set(idx); - port_for_sub.update(cx, |p, cx| { - p.set_value(kind.default_port().to_string(), window, cx); - }); + if is_default { + port_for_sub.update(cx, |p, cx| { + p.set_value(kind.default_port().to_string(), window, cx); + }); + } cx.notify(); } }, diff --git a/gpui-app/src/ui/widgets.rs b/gpui-app/src/ui/widgets.rs index f716d2d..e21f244 100644 --- a/gpui-app/src/ui/widgets.rs +++ b/gpui-app/src/ui/widgets.rs @@ -180,11 +180,24 @@ impl KvEditor { } pub fn pairs(&self, cx: &App) -> Vec<(String, String)> { - self.rows + // key 统一 trim 并去重(保留最后一条):否则带首尾空白的 key + // 永远无法被 {{key}} 模板引用,重复 key 也只有一条能生效。 + let mut out: Vec<(String, String)> = Vec::new(); + for (k, v) in self + .rows .iter() .map(|(k, v)| (k.read(cx).value().to_string(), v.read(cx).value().to_string())) - .filter(|(k, _)| !k.trim().is_empty()) - .collect() + { + let k = k.trim().to_string(); + if k.is_empty() { + continue; + } + match out.iter_mut().find(|(ek, _)| *ek == k) { + Some(slot) => slot.1 = v, + None => out.push((k, v)), + } + } + out } }