From f66cde6494d8854af95d4a162f7666b69190b8ca Mon Sep 17 00:00:00 2001 From: ypshidifu Date: Tue, 22 Sep 2026 21:29:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A2=E6=B5=8B=E7=89=88?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=EF=BC=9A=E6=8E=A2=E7=B4=A2=20keymap.commands?= =?UTF-8?q?=20=E5=92=8C=20dispatch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tui-plugins/oc-session-all.js | 89 ++++++++++++----------------------- 1 file changed, 31 insertions(+), 58 deletions(-) diff --git a/tui-plugins/oc-session-all.js b/tui-plugins/oc-session-all.js index f71c3c4..c281517 100644 --- a/tui-plugins/oc-session-all.js +++ b/tui-plugins/oc-session-all.js @@ -30,93 +30,66 @@ function delay(ms) { export default Plugin.define({ id: "oc-session-all", async setup(context) { - log("[oc-session-all] v2 Plugin loaded! Waiting 3 seconds before toast...") + log("[oc-session-all] v2 Plugin loaded! Exploring keymap.commands and dispatch...") // 先写入测试日志,确保 fs 可用 log("[oc-session-all] FS test: log file created successfully") - // 延时 3 秒,避免 toast 被覆盖 - await delay(3000) + // 延时 5 秒,避免 toast 被覆盖 + await delay(5000) - // ── 探测 context.keymap 结构 ────────────────────────────────────── + // ── 探测 keymap.commands 和 dispatch ────────────────────────────────────── const report = [] - report.push("context keys: " + Object.keys(context).join(", ")) - // 探测 context.keymap if (context.keymap) { - const kmKeys = Object.getOwnPropertyNames(context.keymap) - report.push("keymap props: " + kmKeys.join(", ")) - - // 尝试 keymap.layer - if (typeof context.keymap.layer === "function") { - report.push("keymap.layer is a function") - try { - // 尝试不同的调用方式 - const layerResult = context.keymap.layer({ - commands: [ - { - title: "Show All Sessions", - value: "sessions-all", - slash: { name: "sessions-all", aliases: ["sa"] }, - description: "Display all session records in a dialog", - onSelect: async () => { - log("[oc-session-all] /sessions-all triggered via keymap.layer") - context.ui.toast.show({ - message: "Sessions-all command executed!", - variant: "success", - duration: 3000, - }) - }, - }, - ], - }) - report.push("keymap.layer result type: " + typeof layerResult) - log("[oc-session-all] keymap.layer called successfully, result type: " + typeof layerResult) - } catch (e) { - report.push("keymap.layer ERROR: " + e.message) - log("[oc-session-all] keymap.layer ERROR: " + e.message) - } - } else { - report.push("keymap.layer is NOT a function") - log("[oc-session-all] keymap.layer is NOT a function") - } - - // 尝试 keymap.commands + // 尝试 keymap.commands() if (typeof context.keymap.commands === "function") { - report.push("keymap.commands is a function") try { const commandsResult = context.keymap.commands() - report.push("keymap.commands() result type: " + typeof commandsResult) - log("[oc-session-all] keymap.commands() called, result type: " + typeof commandsResult) + report.push("keymap.commands() returned: " + JSON.stringify(commandsResult).substring(0, 200)) + log("[oc-session-all] keymap.commands() result: " + JSON.stringify(commandsResult).substring(0, 500)) } catch (e) { - report.push("keymap.commands ERROR: " + e.message) - log("[oc-session-all] keymap.commands ERROR: " + e.message) + report.push("keymap.commands() ERROR: " + e.message) + log("[oc-session-all] keymap.commands() ERROR: " + e.message) } - } else if (context.keymap.commands) { - report.push("keymap.commands is an object: " + Object.keys(context.keymap.commands).join(", ")) - log("[oc-session-all] keymap.commands is an object: " + Object.keys(context.keymap.commands).join(", ")) } else { - report.push("keymap.commands is undefined") + report.push("keymap.commands is NOT a function") } // 尝试 keymap.dispatch if (typeof context.keymap.dispatch === "function") { report.push("keymap.dispatch is a function") + + // 尝试触发一个已知的命令 + try { + context.keymap.dispatch("command.palette.show") + report.push("dispatch command.palette.show: SUCCESS") + log("[oc-session-all] dispatch command.palette.show: SUCCESS") + } catch (e) { + report.push("dispatch command.palette.show ERROR: " + e.message) + log("[oc-session-all] dispatch command.palette.show ERROR: " + e.message) + } } else { report.push("keymap.dispatch is NOT a function") } + + // 尝试 keymap.layer 的不同调用方式 + if (typeof context.keymap.layer === "function") { + // 不调用 layer,只记录它存在 + report.push("keymap.layer exists but needs Provider context") + } } const msg = report.join(" | ") - log("[oc-session-all] KEYMAP PROBE: " + msg) + log("[oc-session-all] COMMANDS PROBE: " + msg) - // 再次延时,确保 toast 不被覆盖 - await delay(1000) + // 延时后显示 toast + await delay(2000) try { context.ui.toast.show({ - message: "Keymap probe: " + msg, + message: "Commands probe: " + msg, variant: "info", - duration: 20000, + duration: 25000, }) } catch (e) { log("[oc-session-all] toast.show ERROR: " + e.message)