fix: delete insights + placeholder cursor insertion (Issue #44)
BUG #44: Analysen löschen schlug fehl (kein Auth-Token) FIX: - api.deleteInsight() in api.js hinzugefügt - Analysis.jsx nutzt jetzt api.js mit Error-Handling - Nicht mehr raw fetch() ohne Token BUG: Platzhalter wurden am Ende eingefügt statt an Cursor-Position FIX: - useRef für baseTemplateRef hinzugefügt - Cursor-Position tracking (onClick + onKeyUp) - Insert at cursor: template.slice(0, pos) + placeholder + template.slice(pos) - Focus + Cursor-Position nach Insert wiederhergestellt version: 9.5.2 (bugfix) module: prompts 2.0.2, insights 1.3.1
This commit is contained in:
1 parent
7daa2e40c7
commit
c56d2b2201
3 files changed
+29
-10
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { api } from '../utils/api'
|
||||
import { X, Plus, Trash2, MoveUp, MoveDown, Code } from 'lucide-react'
|
||||
import PlaceholderPicker from './PlaceholderPicker'
|
||||
@@ -39,6 +39,8 @@ export default function UnifiedPromptModal({ prompt, onSave, onClose }) {
|
||||
const [error, setError] = useState(null)
|
||||
const [showPlaceholderPicker, setShowPlaceholderPicker] = useState(false)
|
||||
const [pickerTarget, setPickerTarget] = useState(null) // 'base' or {stage, promptIdx}
|
||||
const [cursorPosition, setCursorPosition] = useState(null) // Track cursor position for insertion
|
||||
const baseTemplateRef = useRef(null)
|
||||
|
||||
// Test functionality
|
||||
const [testing, setTesting] = useState(false)
|
||||
@@ -514,9 +516,12 @@ export default function UnifiedPromptModal({ prompt, onSave, onClose }) {
|
||||
<div style={{ marginBottom: 24 }}>
|
||||
<h3 style={{ fontSize: 16, fontWeight: 600, marginBottom: 12 }}>Template</h3>
|
||||
<textarea
|
||||
ref={baseTemplateRef}
|
||||
className="form-input"
|
||||
value={template}
|
||||
onChange={e => setTemplate(e.target.value)}
|
||||
onClick={e => setCursorPosition(e.target.selectionStart)}
|
||||
onKeyUp={e => setCursorPosition(e.target.selectionStart)}
|
||||
rows={12}
|
||||
placeholder="Prompt-Template mit {{placeholders}}..."
|
||||
style={{ width: '100%', textAlign: 'left', resize: 'vertical', fontFamily: 'monospace', fontSize: 12 }}
|
||||
@@ -799,10 +804,22 @@ export default function UnifiedPromptModal({ prompt, onSave, onClose }) {
|
||||
<PlaceholderPicker
|
||||
onSelect={(placeholder) => {
|
||||
if (pickerTarget === 'base') {
|
||||
// Insert into base template
|
||||
setTemplate(template + placeholder)
|
||||
// Insert into base template at cursor position
|
||||
const pos = cursorPosition ?? template.length
|
||||
const newTemplate = template.slice(0, pos) + placeholder + template.slice(pos)
|
||||
setTemplate(newTemplate)
|
||||
|
||||
// Restore focus and cursor position after insertion
|
||||
setTimeout(() => {
|
||||
if (baseTemplateRef.current) {
|
||||
baseTemplateRef.current.focus()
|
||||
const newPos = pos + placeholder.length
|
||||
baseTemplateRef.current.setSelectionRange(newPos, newPos)
|
||||
setCursorPosition(newPos)
|
||||
}
|
||||
}, 0)
|
||||
} else if (pickerTarget && typeof pickerTarget === 'object') {
|
||||
// Insert into pipeline stage template
|
||||
// Insert into pipeline stage template (append at end for now)
|
||||
const { stage: stageNum, promptIdx } = pickerTarget
|
||||
setStages(stages.map(s => {
|
||||
if (s.stage === stageNum) {
|
||||
|
||||
Reference in new issue
Block a user