pi-cc-extensions 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -417,9 +417,8 @@ export default function sessionReferenceExtension(pi: ExtensionAPI): void {
|
|
|
417
417
|
|
|
418
418
|
getAvailableReferences = getReferences;
|
|
419
419
|
if (ctx.mode === "tui") {
|
|
420
|
-
//
|
|
421
|
-
//
|
|
422
|
-
void getReferences().catch(() => {});
|
|
420
|
+
// 不在这里预取:SessionManager.listAll() 会读完整个会话库,大库要几秒,
|
|
421
|
+
// 而启动并不需要结果。首次 @ 输入由 getSuggestions 触发加载。
|
|
423
422
|
// Register after other session_start handlers. pi-fff claims every @
|
|
424
423
|
// prefix, so a provider installed before it would never see session mentions.
|
|
425
424
|
setTimeout(() => {
|
|
@@ -50,18 +50,37 @@ export class PromptEditor extends CustomEditor {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
type EditorFactory = Parameters<ExtensionContext["ui"]["setEditorComponent"]>[0];
|
|
54
|
+
|
|
55
|
+
const promptEditorFactory: EditorFactory = (tui, theme, keybindings) =>
|
|
56
|
+
new PromptEditor(tui, theme, keybindings, { embedWorkingStatus: true });
|
|
57
|
+
|
|
58
|
+
/** 是否正占着插槽;占据前的工厂用于原样还回去。 */
|
|
59
|
+
let active = false;
|
|
60
|
+
let previousEditorFactory: EditorFactory | undefined;
|
|
61
|
+
|
|
62
|
+
/** 撤销本扩展占据的插槽;从未占用就不碰插槽。 */
|
|
63
|
+
function releasePromptEditor(ctx: ExtensionContext): void {
|
|
64
|
+
if (!active) return;
|
|
65
|
+
ctx.ui.setEditorComponent(previousEditorFactory);
|
|
66
|
+
active = false;
|
|
67
|
+
previousEditorFactory = undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 应用输入框前缀;enableEditorPrefix=false 时只撤自己装的那层。 */
|
|
54
71
|
export function applyPromptEditor(ctx: ExtensionContext): void {
|
|
55
72
|
if (!ctx?.hasUI || typeof ctx.ui?.setEditorComponent !== "function") return;
|
|
56
73
|
try {
|
|
57
|
-
if (config.enableEditorPrefix) {
|
|
58
|
-
ctx
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
ctx.ui.
|
|
74
|
+
if (!config.enableEditorPrefix) {
|
|
75
|
+
releasePromptEditor(ctx);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (!active) {
|
|
79
|
+
// pi 的插槽是硬替换、没有栈,先记住是谁占着,撤销时还回去。
|
|
80
|
+
previousEditorFactory = ctx.ui.getEditorComponent?.();
|
|
81
|
+
active = true;
|
|
64
82
|
}
|
|
83
|
+
ctx.ui.setEditorComponent(promptEditorFactory);
|
|
65
84
|
} catch (err) {
|
|
66
85
|
ctx.ui.notify(
|
|
67
86
|
`prompt editor error: ${err instanceof Error ? err.message : String(err)}`,
|
|
@@ -70,8 +89,8 @@ export function applyPromptEditor(ctx: ExtensionContext): void {
|
|
|
70
89
|
}
|
|
71
90
|
}
|
|
72
91
|
|
|
73
|
-
/**
|
|
92
|
+
/** 恢复本扩展占据前的编辑器;未占用时不动作。 */
|
|
74
93
|
export function clearPromptEditor(ctx: ExtensionContext): void {
|
|
75
94
|
if (!ctx?.hasUI || typeof ctx.ui?.setEditorComponent !== "function") return;
|
|
76
|
-
ctx
|
|
95
|
+
releasePromptEditor(ctx);
|
|
77
96
|
}
|