Fix branch button only appearing on the first code block/table within a message.

keyboardstaff committed Feb 25, 2026 at 19:44 UTC 1d837cc41fce9ee9ee7ff8632c7e393d20594eb6
1 file changed +15 -15
plugins/chat_branching/extensions/webui/set_messages_after_loop/inject-branch-buttons.js
+15 -15
@@ -11,22 +11,22 @@ export default async function injectBranchButtons(context) {
11 for (const { args, result } of context.results) {
12 if (!result?.element || args.no == null) continue;
13
14 - const bar = result.element.querySelector(".step-action-buttons");
15 - if (!bar || bar.querySelector(".action-fork_right")) continue;
16 -
14 const logNo = args.no;
18 - bar.appendChild(
19 - createActionButton("fork_right", "Branch chat", async () => {
20 - const ctxid = globalThis.getContext?.();
21 - if (!ctxid) throw new Error("No active chat");
15 + for (const bar of result.element.querySelectorAll(".step-action-buttons")) {
16 + if (bar.querySelector(".action-fork_right")) continue;
17 + bar.appendChild(
18 + createActionButton("fork_right", "Branch chat", async () => {
19 + const ctxid = globalThis.getContext?.();
20 + if (!ctxid) throw new Error("No active chat");
21
23 - const res = await callJsonApi("/plugins/chat_branching/branch_chat", {
24 - context: ctxid,
25 - log_no: logNo,
26 - });
27 - if (!res?.ok) throw new Error(res?.message || "Branch failed");
28 - chatsStore.selectChat(res.ctxid);
29 - }),
30 - );
22 + const res = await callJsonApi("/plugins/chat_branching/branch_chat", {
23 + context: ctxid,
24 + log_no: logNo,
25 + });
26 + if (!res?.ok) throw new Error(res?.message || "Branch failed");
27 + chatsStore.selectChat(res.ctxid);
28 + }),
29 + );
30 + }
31 }
32 }
\ No newline at end of file