fix: 撤销按钮移出 composer 子树,修复切后台输入框消失,版本 1.1.90(#208)

- 不再注册 conversation.input.right 槽位(该槽位在 composer 的 React 子树内,
  提交阶段一抛错整块输入框被卸载)
- 改用 body 上的 fixed 宿主 + createPortal,渲染树完全脱离 composer
- 按最靠下的 .standardControls 矩形对齐并预留 padding-left,宽度跟随实测
- 会话切换 / resize / scroll 重新对齐;无会话时隐藏并归还留白
- 锚点查找带缓存与节流,只在缺失或掉线时扫 DOM
This commit is contained in:
叫我小杨同学 committed 2026-11-02 16:58:04 +08:00
1 parent bcf28a639c
commit ff4431e1ba
3 files changed
+169 -20

No files matched your search

+146 -19
View File
@@ -9122,29 +9122,156 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
}
/* #208:undo 按钮不再注册进 conversation.input.right。
Android WebView 切后台返回时,宿主 composer 的 React 子树只要在提交阶段抛一次,
整块输入框就会被卸载;把按钮挪到 body 上的 fixed 宿主 + createPortal,
渲染树完全离开 composer,位置按 .standardControls 的矩形对齐。 */
const REWIND_HOST_ATTR = "data-dsh-purge-rewind-host";
const REWIND_RESERVE_PX = 64;
function rewindControlsAnchor() {
if (typeof document === "undefined") return null;
// 取最靠下的那一组:输入框在页面底部;消息工具条里的同名控件更高,别抢。
const list = document.querySelectorAll('[class*="standardControls"]');
let best = null;
let bestTop = -Infinity;
for (let i = 0; i < list.length; i += 1) {
const el = list[i];
if (el.hidden) continue;
const rect = el.getBoundingClientRect();
if (!(rect.width > 0) || !(rect.height > 0)) continue;
if (rect.top >= bestTop) { best = el; bestTop = rect.top; }
}
return best;
}
function placeRewindHost(host, anchor, reserve) {
if (!host || !anchor) return;
const rect = anchor.getBoundingClientRect();
if (!(rect.width > 0) || anchor.hidden) {
host.style.display = "none";
return;
}
const width = host.offsetWidth || 60;
const height = host.offsetHeight || 28;
host.style.display = "block";
host.style.left = Math.max(0, Math.round(rect.left + (reserve - width) / 2)) + "px";
host.style.top = Math.round(rect.top + (rect.height - height) / 2) + "px";
}
function RewindDockMount() {
const t = useT();
const [host, setHost] = useState(null);
const [, bump] = useState(0);
const sessionId = currentSessionId(rewindSessions);
// 没有会话时不留空位:按钮不显示,padding 也一起归还。
const sessionRef = useRef(null);
sessionRef.current = sessionId;
const placeRef = useRef(null);
useEffect(() => {
if (typeof document === "undefined") return undefined;
let el = document.querySelector("[" + REWIND_HOST_ATTR + "]");
if (!el) {
el = document.createElement("div");
el.setAttribute(REWIND_HOST_ATTR, "");
document.body.appendChild(el);
}
el.style.cssText = "position:fixed;z-index:2147482500;display:none;left:0;top:0;";
setHost(el);
let padded = null;
let warned = false;
let lastQuery = 0;
const startedAt = Date.now();
const place = (force) => {
// 缓存锚点 + 1s 节流:只有锚点缺失/掉线时才全文档查一次,
// 否则长会话里每帧扫 [class*=...] 会拖慢滚动。
if (!padded || !padded.isConnected) {
const now = Date.now();
if (force || now - lastQuery > 1000) {
lastQuery = now;
const next = rewindControlsAnchor();
if (padded && padded !== next) padded.style.paddingLeft = padded.dataset.dshpPad || "";
if (next && next !== padded) next.dataset.dshpPad = next.style.paddingLeft || "";
padded = next;
}
}
const anchor = padded;
if (!anchor) {
el.style.display = "none";
if (!warned && Date.now() - startedAt > 5000) {
warned = true;
try { console.warn("[dsh-purge] rewind: composer standardControls anchor missing"); } catch { /* ignore */ }
}
return;
}
// 按钮标签会随失败提示变长,预留宽度跟着实测宽度走,避免压到模型选择器。
const reserve = Math.max(REWIND_RESERVE_PX, (el.offsetWidth || 60) + 12);
const pad = sessionRef.current ? reserve + "px" : (anchor.dataset.dshpPad || "");
if (anchor.style.paddingLeft !== pad) anchor.style.paddingLeft = pad;
if (!sessionRef.current) {
el.style.display = "none";
return;
}
placeRewindHost(el, anchor, reserve);
};
place(true);
placeRef.current = place;
const onMove = () => place(false);
const iv = setInterval(onMove, 500);
window.addEventListener("resize", onMove);
document.addEventListener("scroll", onMove, true);
return () => {
clearInterval(iv);
placeRef.current = null;
window.removeEventListener("resize", onMove);
document.removeEventListener("scroll", onMove, true);
if (padded) {
padded.style.paddingLeft = padded.dataset.dshpPad || "";
delete padded.dataset.dshpPad;
}
try { el.remove(); } catch { /* ignore */ }
};
}, []);
// 会话切换/首次挂载时立刻对齐,不用等 500ms 定时器。
useEffect(() => {
if (placeRef.current) placeRef.current(true);
}, [sessionId, host]);
useEffect(() => {
const offs = [];
const watch = (store) => {
try {
if (store && typeof store.subscribe === "function") {
offs.push(store.subscribe(() => bump((n) => (n + 1) % 1e9)));
}
} catch { /* ignore */ }
};
watch(rewindWorkspace && rewindWorkspace.selection);
watch(rewindSessions && rewindSessions.list);
const iv = setInterval(() => bump((n) => (n + 1) % 1e9), 2000);
return () => {
for (const off of offs) { try { off(); } catch { /* ignore */ } }
clearInterval(iv);
};
}, []);
if (!host || !sessionId) return null;
try {
const rd = require("react-dom");
if (rd && typeof rd.createPortal === "function") {
return rd.createPortal(h(RewindSafe, { sessionId, t }), host);
}
} catch { /* host 可能没暴露 react-dom */ }
return null;
}
function installRewindUi(ctx) {
rewindHost = ctx;
rewindSessions = ctx.sessions;
rewindWorkspace = ctx.uiWorkspace || null;
rewindConversation = ctx.conversation || null;
ctx.slots.inject("conversation.input.right", () => ctx.slots.register({
name: "conversation.input.right",
id: "dsh-purge-rewind",
order: 20,
inject: (sessionId) => ({
sessionId,
t: ctx.locale.bind(NS),
}),
}, RewindSafe));
// ctx.slots.inject("conversation.input.right", () => ctx.slots.register({
// name: "conversation.input.right",
// id: "dsh-purge-continue",
// order: 21,
// inject: (sessionId) => ({
// sessionId,
// t: ctx.locale.bind(NS),
// }),
// }, ContinueSafe));
ctx.effect(() => installRewindWatch(ctx), "dsh-purge: rewind watch");
}
@@ -9201,7 +9328,7 @@ body[data-ds-dark-theme] .rt-scope-testing,.dshp-dock[data-theme="dusk"] .rt-sco
name: "shell.overlay",
id: "dsh-purge-dock",
order: 50,
}, () => h(react.Fragment, null, h(WelcomeNotice), h(PurgeLauncher), h(PurgeDock), h(HeroNewSessionMount), h(TabRowPurgeMount), h(EnvAdaptSendGate))));
}, () => h(react.Fragment, null, h(WelcomeNotice), h(PurgeLauncher), h(PurgeDock), h(HeroNewSessionMount), h(TabRowPurgeMount), h(EnvAdaptSendGate), h(RewindDockMount))));
try {
if (typeof ctx.inject === "function") {
ctx.inject(["sessions", "uiWorkspace", "workspaces", "conversation"], (host) => installRewindUi(host));
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "dsh-purge",
"version": "1.1.89",
"version": "1.1.90",
"description": "DeepSeek Harness 破甲:让所有模型都能破甲,不同模型可换不同提示词;默认提示词面向国模「小码酱」。Jailbreak for every model — swap prompts per model. 求 Star 收藏 ⭐ 如要二开,请查看署名要求部分",
"type": "module",
"main": "lib/index.js",
+22
View File
@@ -1,3 +1,25 @@
# 1.1.90
## 中文
- 版本 **1.1.90**。
- **#208 Android 切后台回来输入框整块消失**:撤销按钮原先注册在宿主的 `conversation.input.right` 槽位,这个槽位渲染在 composer 的 React 子树里。宿主在提交阶段只要抛一次错,React 会把整棵树卸载,症状就是输入框连带按钮一起没了。
- 撤销按钮不再走任何槽位。改为在 `body` 上挂一个 `position: fixed` 的宿主节点,用 `createPortal` 把按钮传进去,渲染树完全脱离 composer;composer 内部再出错也牵连不到它。
- 位置按最靠下的那组 `.standardControls`(就是 composer 底部工具条)的矩形实时对齐,并给它留 `padding-left` 空位,不遮住模型选择器;预留宽度跟着按钮实测宽度走。
- 会话切换、窗口尺寸变化、页面滚动都会重新对齐;没有会话时按钮不显示、留白也一起归还。
- 锚点查找带缓存和节流,只在锚点缺失或掉线时才扫一次 DOM,长会话滚动不受影响。
- **验证**:`client.js` 语法检查通过;`conversation.input.right` 在本插件中已无任何注册点;双宿主 `standardControls` 类名核对一致。
## English
- **1.1.90**.
- **#208 the whole composer vanished after switching apps**: the undo button was registered into the host's `conversation.input.right` slot, which renders inside the composer's React subtree. One throw during a commit phase makes React unmount that tree, and the input box goes with it.
- The undo button no longer uses any slot. It renders through `createPortal` into a `position: fixed` host appended to `body`, fully outside the composer subtree, so a composer error can no longer take it down.
- It aligns itself to the rectangle of the bottom-most `.standardControls` (the composer toolbar) and reserves `padding-left` there so the model picker is not covered; the reserved width follows the button's measured width.
- It re-aligns on session change, resize and scroll, and releases both the button and the reserved space when there is no session.
- Anchor lookup is cached and throttled: the DOM is scanned only when the anchor is missing or detached, so long chats keep scrolling smoothly.
- **Verification**: `client.js` passes the syntax check; no `conversation.input.right` registration remains in the plugin; the `standardControls` class name matches on both hosts.
# 1.1.89
## 中文