fix(promptlib): 1.8.18 插入变量改回确定性 splice,重复插入不再偏移;样式保持 1.8.8 基线
validate / validate (push) Canceled after 0s

This commit is contained in:
qiqi committed 2026-11-23 10:04:56 +08:00
1 parent 3a563950ba
commit ced0482ed8
2 files changed
+8 -16

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/promptlib",
"private": true,
"version": "1.8.17",
"version": "1.8.18",
"description": "提示词库:右栏提示词列表(搜索/分组/收藏/新建编辑/插入画布/复制/删除),数据由宿主 promptlib 能力提供",
"ibwPlugin": {
"id": "promptlib",
+7 -15
View File
@@ -1556,23 +1556,15 @@
insVarBtn.addEventListener('pointerdown', function (e) { e.preventDefault(); rememberSel() })
insVarBtn.addEventListener('click', function () {
var v = textIn.value
textIn.focus()
// 先把选区恢复到用户最后的光标位置,再交给浏览器原生插入
try { textIn.setSelectionRange(Math.min(lastSel.s, v.length), Math.min(lastSel.e, v.length)) } catch (e) { /* ignore */ }
var s = textIn.selectionStart, e = textIn.selectionEnd
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 + '}'
var ok = false
try { ok = document.execCommand('insertText', false, ins) } catch (err) { ok = false }
if (!ok) {
textIn.value = v.slice(0, s) + ins + v.slice(e)
textIn.setSelectionRange(s + 1, s + 1 + name.length)
} else {
var pos = textIn.selectionStart
textIn.setSelectionRange(pos - ins.length + 1, pos - 1)
}
lastSel = { s: textIn.selectionStart, e: textIn.selectionEnd }
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)
@@ -1771,7 +1763,7 @@
global.IWBPluginHost.register({
id: 'promptlib',
name: '提示词库',
version: '1.8.17',
version: '1.8.18',
apiVersion: 1,
capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite'],
data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 },