fix: KvEditor key 规范化与传输端口往返保留自定义值
- KvEditor 的 key 统一 trim 并去重(保留最后一条):带首尾空白的 key
永远无法被 {{key}} 模板引用,重复 key 只有首条生效
- 切换传输方式仅当当前端口仍是某个默认端口时才跟随切换:
WSS:9443 → TCP → WSS 的往返不再丢失自定义端口
This commit is contained in:
@@ -253,10 +253,17 @@ impl ConnectionForm {
|
|||||||
if last_transport.get() == idx {
|
if last_transport.get() == idx {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 端口只在仍是某个默认端口(而非用户自定义值)时才跟随切换:
|
||||||
|
// 否则 WSS:9443 → TCP → WSS 的往返会把 9443 静默丢失
|
||||||
|
let current = port_for_sub.read(cx).value().trim().parse::<u16>().ok();
|
||||||
|
let is_default = matches!(current, Some(p) if
|
||||||
|
TransportKind::ALL.iter().any(|k| k.default_port() == p));
|
||||||
last_transport.set(idx);
|
last_transport.set(idx);
|
||||||
|
if is_default {
|
||||||
port_for_sub.update(cx, |p, cx| {
|
port_for_sub.update(cx, |p, cx| {
|
||||||
p.set_value(kind.default_port().to_string(), window, cx);
|
p.set_value(kind.default_port().to_string(), window, cx);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -180,11 +180,24 @@ impl KvEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn pairs(&self, cx: &App) -> Vec<(String, String)> {
|
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()
|
.iter()
|
||||||
.map(|(k, v)| (k.read(cx).value().to_string(), v.read(cx).value().to_string()))
|
.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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user