From 2ef5133bcdc29d9c25f3a5276e10ee18359fe08b Mon Sep 17 00:00:00 2001 From: JoeAllen <2494136784@qq.com> Date: Tue, 29 Sep 2026 10:34:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20KvEditor=20key=20=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E5=8C=96=E4=B8=8E=E4=BC=A0=E8=BE=93=E7=AB=AF=E5=8F=A3=E5=BE=80?= =?UTF-8?q?=E8=BF=94=E4=BF=9D=E7=95=99=E8=87=AA=E5=AE=9A=E4=B9=89=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - KvEditor 的 key 统一 trim 并去重(保留最后一条):带首尾空白的 key 永远无法被 {{key}} 模板引用,重复 key 只有首条生效 - 切换传输方式仅当当前端口仍是某个默认端口时才跟随切换: WSS:9443 → TCP → WSS 的往返不再丢失自定义端口 --- gpui-app/src/ui/connection_form.rs | 13 ++++++++++--- gpui-app/src/ui/widgets.rs | 19 ++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) 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 } }