Skip to content

Commit 7f7f4c9

Browse files
committed
2.0.4 修复标签和历史功能无法使用问题
1 parent 8c7436f commit 7f7f4c9

4 files changed

Lines changed: 64 additions & 28 deletions

File tree

js/modules/history.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class HistoryManager {
2020
static onCloseCallback = null;
2121
static currentNodeId = null; // 当前节点ID
2222
static currentInputId = null; // 当前输入框ID
23+
static currentWidgetKey = null; // 当前widgetKey
2324
static eventCleanups = []; // 事件清理函数数组
2425
static activeTooltip = null; // 当前活动的 tooltip
2526

@@ -30,9 +31,10 @@ class HistoryManager {
3031
const { anchorButton, nodeId, inputId, onClose } = params;
3132

3233
try {
33-
// 保存当前节点和输入框ID
34+
// 保存数据
3435
this.currentNodeId = nodeId;
3536
this.currentInputId = inputId;
37+
this.currentWidgetKey = params.widgetKey || null;
3638

3739
// logger.debug(`历史弹窗 | 触发显示 | 节点:${nodeId} | 输入框:${inputId}`);
3840

@@ -198,7 +200,8 @@ class HistoryManager {
198200
this.hideHistoryPopup();
199201
try {
200202
// 获取当前输入框内容
201-
const inputEl = window.PromptAssistantInputWidgetMap?.[`${nodeId}_${this.currentInputId}`]?.inputEl;
203+
const mapping = UIToolkit._findMapping(nodeId, this.currentInputId, this.currentWidgetKey);
204+
const inputEl = mapping?.inputEl;
202205
const currentContent = inputEl?.value || '';
203206

204207
// 清除当前节点的历史
@@ -218,8 +221,8 @@ class HistoryManager {
218221
}
219222

220223
// 更新按钮状态
221-
if (window.PromptAssistantInputWidgetMap?.[`${nodeId}_${this.currentInputId}`]?.widget) {
222-
const widget = window.PromptAssistantInputWidgetMap[`${nodeId}_${this.currentInputId}`].widget;
224+
if (mapping?.widget) {
225+
const widget = mapping.widget;
223226
UIToolkit.updateUndoRedoButtonState(widget, HistoryCacheService);
224227
}
225228

@@ -242,7 +245,8 @@ class HistoryManager {
242245
this.hideHistoryPopup();
243246
try {
244247
// 获取当前输入框内容
245-
const inputEl = window.PromptAssistantInputWidgetMap?.[`${nodeId}_${this.currentInputId}`]?.inputEl;
248+
const mapping = UIToolkit._findMapping(nodeId, this.currentInputId, this.currentWidgetKey);
249+
const inputEl = mapping?.inputEl;
246250
const currentContent = inputEl?.value || '';
247251

248252
// 清除所有历史
@@ -262,8 +266,8 @@ class HistoryManager {
262266
}
263267

264268
// 更新按钮状态
265-
if (window.PromptAssistantInputWidgetMap?.[`${nodeId}_${this.currentInputId}`]?.widget) {
266-
const widget = window.PromptAssistantInputWidgetMap[`${nodeId}_${this.currentInputId}`].widget;
269+
if (mapping?.widget) {
270+
const widget = mapping.widget;
267271
UIToolkit.updateUndoRedoButtonState(widget, HistoryCacheService);
268272
}
269273

@@ -513,7 +517,8 @@ class HistoryManager {
513517
// 使用UIToolkit写入内容到输入框
514518
const success = UIToolkit.writeToInput(item.content, this.currentNodeId, this.currentInputId, {
515519
highlight: true,
516-
focus: true
520+
focus: true,
521+
widgetKey: this.currentWidgetKey
517522
});
518523

519524
if (success) {

js/modules/tag.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class TagManager {
154154
static searchTimeout = null; // 搜索延迟定时器
155155
static currentNodeId = null;
156156
static currentInputId = null;
157+
static currentWidgetKey = null;
157158
static activeTooltip = null;
158159
static usedTags = new Map(); // 存储已使用标签的Map: key为标签值,value为对应的DOM元素
159160
static currentCsvFile = null; // 当前选中的CSV文件
@@ -180,8 +181,7 @@ class TagManager {
180181
* 检查标签是否已插入到输入框中
181182
*/
182183
static isTagUsed(tagValue, nodeId, inputId) {
183-
const mappingKey = `${nodeId}_${inputId}`;
184-
const mapping = window.PromptAssistantInputWidgetMap?.[mappingKey];
184+
const mapping = UIToolkit._findMapping(nodeId, inputId, this.currentWidgetKey);
185185
if (!mapping || !mapping.inputEl) return false;
186186

187187
// 检查输入框内容是否包含标签的任一格式
@@ -208,8 +208,7 @@ class TagManager {
208208
e.stopPropagation();
209209

210210
// 获取输入框信息
211-
const mappingKey = `${this.currentNodeId}_${this.currentInputId}`;
212-
const mapping = window.PromptAssistantInputWidgetMap?.[mappingKey];
211+
const mapping = UIToolkit._findMapping(this.currentNodeId, this.currentInputId, this.currentWidgetKey);
213212
if (!mapping || !mapping.inputEl) return;
214213

215214
const inputEl = mapping.inputEl;
@@ -288,7 +287,8 @@ class TagManager {
288287
// 插入到光标位置
289288
UIToolkit.insertAtCursor(insertFormat, this.currentNodeId, this.currentInputId, {
290289
highlight: true,
291-
keepFocus: true
290+
keepFocus: true,
291+
widgetKey: this.currentWidgetKey
292292
});
293293

294294
// 更新光标位置到插入内容之后
@@ -323,8 +323,7 @@ class TagManager {
323323
* 从输入框中移除标签
324324
*/
325325
static removeTag(tagValue, nodeId, inputId, keepFocus = true) {
326-
const mappingKey = `${nodeId}_${inputId}`;
327-
const mapping = window.PromptAssistantInputWidgetMap?.[mappingKey];
326+
const mapping = UIToolkit._findMapping(nodeId, inputId, this.currentWidgetKey);
328327

329328
if (mapping && mapping.inputEl) {
330329
const inputEl = mapping.inputEl;
@@ -3258,8 +3257,7 @@ class TagManager {
32583257
const startTime = performance.now();
32593258

32603259
// 获取输入框值
3261-
const mappingKey = `${nodeId}_${inputId}`;
3262-
const mapping = window.PromptAssistantInputWidgetMap?.[mappingKey];
3260+
const mapping = UIToolkit._findMapping(nodeId, inputId, (nodeId === this.currentNodeId && inputId === this.currentInputId) ? this.currentWidgetKey : null);
32633261
if (!mapping || !mapping.inputEl) return { cacheCount: 0, matchedCount: 0 };
32643262

32653263
const inputValue = mapping.inputEl.value;
@@ -3697,6 +3695,7 @@ class TagManager {
36973695
// 保存当前节点和输入框ID
36983696
this.currentNodeId = nodeId;
36993697
this.currentInputId = inputId;
3698+
this.currentWidgetKey = options.widgetKey || null;
37003699
this.onTagSelectCallback = onTagSelect;
37013700

37023701
// 清理现有事件监听
@@ -4947,8 +4946,7 @@ class TagManager {
49474946
* 更新所有标签的状态
49484947
*/
49494948
static updateAllTagsState(nodeId, inputId) {
4950-
const mappingKey = `${nodeId}_${inputId}`;
4951-
const mapping = window.PromptAssistantInputWidgetMap?.[mappingKey];
4949+
const mapping = UIToolkit._findMapping(nodeId, inputId, (nodeId === this.currentNodeId && inputId === this.currentInputId) ? this.currentWidgetKey : null);
49524950
if (!mapping || !mapping.inputEl) return;
49534951

49544952
const inputValue = mapping.inputEl.value;
@@ -5056,8 +5054,7 @@ class TagManager {
50565054
const usedTags = new Map();
50575055

50585056
// 从输入框中获取标签
5059-
const mappingKey = `${this.currentNodeId}_${this.currentInputId}`;
5060-
const mapping = window.PromptAssistantInputWidgetMap?.[mappingKey];
5057+
const mapping = UIToolkit._findMapping(this.currentNodeId, this.currentInputId, this.currentWidgetKey);
50615058

50625059
if (mapping && mapping.inputEl) {
50635060
// 从标签缓存中获取所有标签

js/utils/UIToolkit.js

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ class UIToolkit {
492492
anchorButton: e.currentTarget,
493493
nodeId: widget.nodeId,
494494
inputId: widget.inputId,
495+
widgetKey: widget.widgetKey,
495496
buttonInfo: buttonInfo,
496497
onClose: () => {
497498
// 弹窗关闭时,如果当前按钮仍为激活状态,则重置
@@ -718,9 +719,8 @@ class UIToolkit {
718719
/**
719720
* 写入内容到输入框
720721
*/
721-
static writeToInput(content, nodeId, inputId, options = { highlight: true, focus: false }) {
722-
const mappingKey = `${nodeId}_${inputId}`;
723-
const mapping = window.PromptAssistantInputWidgetMap?.[mappingKey];
722+
static writeToInput(content, nodeId, inputId, options = { highlight: true, focus: false, widgetKey: null }) {
723+
const mapping = this._findMapping(nodeId, inputId, options.widgetKey);
724724

725725
if (mapping && mapping.inputEl) {
726726
const inputEl = mapping.inputEl;
@@ -774,9 +774,8 @@ class UIToolkit {
774774
/**
775775
* 在光标位置插入内容
776776
*/
777-
static insertAtCursor(content, nodeId, inputId, options = { highlight: true, keepFocus: true }) {
778-
const mappingKey = `${nodeId}_${inputId}`;
779-
const mapping = window.PromptAssistantInputWidgetMap?.[mappingKey];
777+
static insertAtCursor(content, nodeId, inputId, options = { highlight: true, keepFocus: true, widgetKey: null }) {
778+
const mapping = this._findMapping(nodeId, inputId, options.widgetKey);
780779

781780
if (mapping && mapping.inputEl) {
782781
const inputEl = mapping.inputEl;
@@ -857,6 +856,41 @@ class UIToolkit {
857856
}
858857
}
859858

859+
/**
860+
* 根据 nodeID 和 inputID 查找映射关系的辅助方法
861+
* 优先使用 widgetKey,如果未提供则尝试匹配唯一映射
862+
*/
863+
static _findMapping(nodeId, inputId, widgetKey = null) {
864+
if (widgetKey) {
865+
const mapping = window.PromptAssistantInputWidgetMap?.[widgetKey];
866+
if (mapping) return mapping;
867+
}
868+
869+
// 尝试使用旧格式 key
870+
const oldKey = `${nodeId}_${inputId}`;
871+
const oldMapping = window.PromptAssistantInputWidgetMap?.[oldKey];
872+
if (oldMapping) return oldMapping;
873+
874+
// 如果仍未找到,尝试在所有映射中查找匹配 nodeId 和 inputId 的项
875+
// 这在 graphId 无法确定的情况下非常有用
876+
const mappings = Object.values(window.PromptAssistantInputWidgetMap || {});
877+
const matches = mappings.filter(m =>
878+
(m.widget?.nodeId == nodeId && m.widget?.inputId == inputId) ||
879+
(m.inputEl && m.inputEl._nodeId == nodeId && m.inputEl._inputId == inputId)
880+
);
881+
882+
if (matches.length === 1) {
883+
return matches[0];
884+
} else if (matches.length > 1) {
885+
logger.warn(`查找映射 | 结果:冲突 | 找到多个匹配项 | 节点:${nodeId} | 输入框:${inputId}`);
886+
// 如果有多个匹配,尝试匹配 nodeId 且没有 graphId 的那个(旧版本)
887+
const bestMatch = matches.find(m => !m.widgetKey || !m.widgetKey.includes('_'));
888+
return bestMatch || matches[0];
889+
}
890+
891+
return null;
892+
}
893+
860894
/**
861895
* 为输入框添加高亮动画效果
862896
*/

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "prompt-assistant"
3-
version = "2.0.3"
3+
version = "2.0.4"
44
description = "提示词小助手可以一键调用GLM、gemini、ChatGPT、Grok、Qwen等在线大模型以及本地Ollama大模型。实现提示词、markdown节点翻译、润色扩写、图片视频反推。支持提示词预设实现一键插入、历史提示词查找等功能。是一个全能型提示词插件。This prompt assistant plugin supports one-click access to online LLMs including GLM, Gemini, ChatGPT, Grok, Qwen, and local Ollama models. It provides prompt generation, Markdown node translation, polishing, expansion, image and video prompt reverse engineering, and more. The plugin also features prompt presets for one‑click insertion and prompt history search, making it an all‑in‑one prompt utility for ComfyUI."
55
readme = "README.md"
66
license = {text = "GNU General Public License v3"}

0 commit comments

Comments
 (0)