mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
This commit is contained in:
committed by
GitHub
parent
72c07e8ad2
commit
f081f5a73c
@@ -158,23 +158,19 @@ export function IterationBadges({ nodeId, data, iterationType }: IterationBadges
|
||||
const handleEditorChange = useCallback(
|
||||
(value: string) => {
|
||||
if (isPreview) return
|
||||
|
||||
// Capture cursor first to minimize staleness in dropdown logic
|
||||
const textarea = editorContainerRef.current?.querySelector(
|
||||
'textarea'
|
||||
) as HTMLTextAreaElement | null
|
||||
const cursorPos = textarea?.selectionStart ?? cursorPosition
|
||||
if (textarea) {
|
||||
textareaRef.current = textarea
|
||||
}
|
||||
setCursorPosition(cursorPos)
|
||||
|
||||
collaborativeUpdateIterationCollection(nodeId, iterationType, value)
|
||||
|
||||
const triggerCheck = checkTagTrigger(value, cursorPos)
|
||||
setShowTagDropdown(triggerCheck.show)
|
||||
const textarea = editorContainerRef.current?.querySelector('textarea')
|
||||
if (textarea) {
|
||||
textareaRef.current = textarea
|
||||
const cursorPos = textarea.selectionStart || 0
|
||||
setCursorPosition(cursorPos)
|
||||
|
||||
const triggerCheck = checkTagTrigger(value, cursorPos)
|
||||
setShowTagDropdown(triggerCheck.show)
|
||||
}
|
||||
},
|
||||
[nodeId, iterationType, collaborativeUpdateIterationCollection, isPreview, cursorPosition]
|
||||
[nodeId, iterationType, collaborativeUpdateIterationCollection, isPreview]
|
||||
)
|
||||
|
||||
// Handle tag selection
|
||||
|
||||
@@ -446,25 +446,24 @@ export function Code({
|
||||
value={code}
|
||||
onValueChange={(newCode) => {
|
||||
if (!isCollapsed && !isAiStreaming && !isPreview && !disabled) {
|
||||
// Capture cursor first to minimize staleness in dropdown logic
|
||||
const textarea = editorRef.current?.querySelector(
|
||||
'textarea'
|
||||
) as HTMLTextAreaElement | null
|
||||
const pos = textarea?.selectionStart ?? cursorPosition
|
||||
setCursorPosition(pos)
|
||||
|
||||
setCode(newCode)
|
||||
setStoreValue(newCode)
|
||||
|
||||
const tagTrigger = checkTagTrigger(newCode, pos)
|
||||
setShowTags(tagTrigger.show)
|
||||
if (!tagTrigger.show) {
|
||||
setActiveSourceBlockId(null)
|
||||
}
|
||||
const textarea = editorRef.current?.querySelector('textarea')
|
||||
if (textarea) {
|
||||
const pos = textarea.selectionStart
|
||||
setCursorPosition(pos)
|
||||
|
||||
const envVarTrigger = checkEnvVarTrigger(newCode, pos)
|
||||
setShowEnvVars(envVarTrigger.show)
|
||||
setSearchTerm(envVarTrigger.show ? envVarTrigger.searchTerm : '')
|
||||
const tagTrigger = checkTagTrigger(newCode, pos)
|
||||
setShowTags(tagTrigger.show)
|
||||
if (!tagTrigger.show) {
|
||||
setActiveSourceBlockId(null)
|
||||
}
|
||||
|
||||
const envVarTrigger = checkEnvVarTrigger(newCode, pos)
|
||||
setShowEnvVars(envVarTrigger.show)
|
||||
setSearchTerm(envVarTrigger.show ? envVarTrigger.searchTerm : '')
|
||||
}
|
||||
}
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
|
||||
@@ -150,14 +150,13 @@ export function ComboBox({
|
||||
const newValue = e.target.value
|
||||
const newCursorPosition = e.target.selectionStart ?? 0
|
||||
|
||||
// Update cursor first to reduce staleness for dropdown logic
|
||||
setCursorPosition(newCursorPosition)
|
||||
|
||||
// Update store value immediately (allow free text)
|
||||
if (!isPreview) {
|
||||
setStoreValue(newValue)
|
||||
}
|
||||
|
||||
setCursorPosition(newCursorPosition)
|
||||
|
||||
// Check for environment variables trigger
|
||||
const envVarTrigger = checkEnvVarTrigger(newValue, newCursorPosition)
|
||||
setShowEnvVars(envVarTrigger.show)
|
||||
|
||||
@@ -148,9 +148,6 @@ export function LongInput({
|
||||
const newValue = e.target.value
|
||||
const newCursorPosition = e.target.selectionStart ?? 0
|
||||
|
||||
// Update cursor first to minimize state staleness for dropdown selection logic
|
||||
setCursorPosition(newCursorPosition)
|
||||
|
||||
// Update local content immediately
|
||||
setLocalContent(newValue)
|
||||
|
||||
@@ -161,6 +158,8 @@ export function LongInput({
|
||||
setStoreValue(newValue)
|
||||
}
|
||||
|
||||
setCursorPosition(newCursorPosition)
|
||||
|
||||
// Check for environment variables trigger
|
||||
const envVarTrigger = checkEnvVarTrigger(newValue, newCursorPosition)
|
||||
setShowEnvVars(envVarTrigger.show)
|
||||
|
||||
@@ -106,9 +106,6 @@ export function ShortInput({
|
||||
const newValue = e.target.value
|
||||
const newCursorPosition = e.target.selectionStart ?? 0
|
||||
|
||||
// Update cursor first to minimize state staleness for dropdown selection logic
|
||||
setCursorPosition(newCursorPosition)
|
||||
|
||||
if (onChange) {
|
||||
onChange(newValue)
|
||||
} else if (!isPreview) {
|
||||
@@ -116,6 +113,8 @@ export function ShortInput({
|
||||
setStoreValue(newValue)
|
||||
}
|
||||
|
||||
setCursorPosition(newCursorPosition)
|
||||
|
||||
// Check for environment variables trigger
|
||||
const envVarTrigger = checkEnvVarTrigger(newValue, newCursorPosition)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user