diff --git a/plugins/index.json b/plugins/index.json index 5e797bb..9055af1 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -44,9 +44,9 @@ "dir": "promptlib", "main": "main.js", "style": "styles.css", - "version": "1.8.17", + "version": "1.8.18", "files": { - "main.js": "236507e6ee1d0bd0fe911145515ba9e20aa2c6666c5bbff221eb6565fb164146", + "main.js": "65f209d8a1d6706aa5e78ad5e9d466d20d3ad5d4bd9c91f2c172d10b594c1137", "styles.css": "ad03f9581e8ae57465098f6c7a3f664a0309680d74ff6384a12801737df87085" } }, diff --git a/plugins/promptlib/main.js b/plugins/promptlib/main.js index ea3d929..e746137 100644 --- a/plugins/promptlib/main.js +++ b/plugins/promptlib/main.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 }, diff --git a/plugins/promptlib/manifest.json b/plugins/promptlib/manifest.json index 6f7e809..173e4e7 100644 --- a/plugins/promptlib/manifest.json +++ b/plugins/promptlib/manifest.json @@ -1,7 +1,7 @@ { "id": "promptlib", "name": "提示词库", - "version": "1.8.17", + "version": "1.8.18", "apiVersion": 1, "main": "main.js", "style": "styles.css", @@ -13,7 +13,7 @@ "提示词" ], "files": { - "main.js": "236507e6ee1d0bd0fe911145515ba9e20aa2c6666c5bbff221eb6565fb164146", + "main.js": "65f209d8a1d6706aa5e78ad5e9d466d20d3ad5d4bd9c91f2c172d10b594c1137", "styles.css": "ad03f9581e8ae57465098f6c7a3f664a0309680d74ff6384a12801737df87085" } }