From 980481a897c8f8709b3d828425313c466c13a488 Mon Sep 17 00:00:00 2001 From: qiqi Date: Mon, 23 Nov 2026 09:40:31 +0800 Subject: [PATCH] =?UTF-8?q?chore(plugins):=20promptlib=201.8.9=20=E5=B8=82?= =?UTF-8?q?=E5=9C=BA=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/index.json | 4 ++-- plugins/promptlib/main.js | 20 ++++++++++++++------ plugins/promptlib/manifest.json | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/plugins/index.json b/plugins/index.json index 9e65b22..fff7811 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -44,9 +44,9 @@ "dir": "promptlib", "main": "main.js", "style": "styles.css", - "version": "1.8.8", + "version": "1.8.9", "files": { - "main.js": "91fde4bcfa888b04ee2b0e79a05d951a56247bc76ecd11b5d9500131df11d542", + "main.js": "7072f8ad6e80accc6cef1a42b44f1ed963f71fe090b75848fda70bc373cd05e2", "styles.css": "70cc02f98bed580f70ef9c71009dde29e01a92684c28d69016438d49c1e0a95b" } }, diff --git a/plugins/promptlib/main.js b/plugins/promptlib/main.js index d7306fb..705ff48 100644 --- a/plugins/promptlib/main.js +++ b/plugins/promptlib/main.js @@ -1545,18 +1545,26 @@ syncTimer = setTimeout(function () { varEd.sync(textIn.value) }, 200) }) // v1.6.2:正文上方「插入变量」——在光标处插入 {变量} 并选中变量名,直接打字即可替换 + var lastSel = { s: 0, e: 0 } + function rememberSel () { + lastSel.s = typeof textIn.selectionStart === 'number' ? textIn.selectionStart : 0 + lastSel.e = typeof textIn.selectionEnd === 'number' ? textIn.selectionEnd : lastSel.s + } + ;['keyup', 'mouseup', 'input', 'select', 'blur'].forEach(function (ev) { textIn.addEventListener(ev, rememberSel) }) var insVarBtn = el('button', { class: 'iwb-btn iwb-btn-sm iwb-plp-insvar', title: '在光标处插入 {变量}', text: '+ 插入变量' }) + // 按钮按下时不要抢走 textarea 的焦点/选区(否则插入点会漂移到上一次位置) + insVarBtn.addEventListener('pointerdown', function (e) { e.preventDefault(); rememberSel() }) insVarBtn.addEventListener('click', function () { var v = textIn.value - var s = (typeof textIn.selectionStart === 'number') ? textIn.selectionStart : v.length - var e = (typeof textIn.selectionEnd === 'number') ? textIn.selectionEnd : v.length + var s = Math.min(Math.max(lastSel.s || 0, 0), v.length) + var e = Math.min(Math.max(lastSel.e == null ? s : lastSel.e, s), v.length) var name = s !== e ? String(v.slice(s, e)).replace(/\s+/g, '').slice(0, 24) : '新变量' if (!name) name = '新变量' var ins = '{' + name + '}' - textIn.value = v.slice(0, s) + ins + v.slice(e) - textIn.selectionStart = s + 1 - textIn.selectionEnd = s + 1 + name.length textIn.focus() + textIn.value = v.slice(0, s) + ins + v.slice(e) + textIn.setSelectionRange(s + 1, s + 1 + name.length) + lastSel = { s: s + 1, e: s + 1 + name.length } dirty = true paintHl() varEd.sync(textIn.value) @@ -1755,7 +1763,7 @@ global.IWBPluginHost.register({ id: 'promptlib', name: '提示词库', - version: '1.8.8', + version: '1.8.9', apiVersion: 1, capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite'], data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 }, diff --git a/plugins/promptlib/manifest.json b/plugins/promptlib/manifest.json index 5100f00..57010b5 100644 --- a/plugins/promptlib/manifest.json +++ b/plugins/promptlib/manifest.json @@ -1,7 +1,7 @@ { "id": "promptlib", "name": "提示词库", - "version": "1.8.8", + "version": "1.8.9", "apiVersion": 1, "main": "main.js", "style": "styles.css", @@ -13,7 +13,7 @@ "提示词" ], "files": { - "main.js": "91fde4bcfa888b04ee2b0e79a05d951a56247bc76ecd11b5d9500131df11d542", + "main.js": "7072f8ad6e80accc6cef1a42b44f1ed963f71fe090b75848fda70bc373cd05e2", "styles.css": "70cc02f98bed580f70ef9c71009dde29e01a92684c28d69016438d49c1e0a95b" } }