diff --git a/promptlib/package.json b/promptlib/package.json index 0cbfa64..52e0db6 100644 --- a/promptlib/package.json +++ b/promptlib/package.json @@ -1,7 +1,7 @@ { "name": "@iwb-plugin/promptlib", "private": true, - "version": "1.8.17", + "version": "1.8.18", "description": "提示词库:右栏提示词列表(搜索/分组/收藏/新建编辑/插入画布/复制/删除),数据由宿主 promptlib 能力提供", "ibwPlugin": { "id": "promptlib", diff --git a/promptlib/src/index.js b/promptlib/src/index.js index ea3d929..e746137 100644 --- a/promptlib/src/index.js +++ b/promptlib/src/index.js @@ -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 },