Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ export const Code = memo(function Code({
* @param newValue - The new code value with the selected tag inserted
*/
const handleTagSelect = (newValue: string) => {
const textarea = editorRef.current?.querySelector('textarea')
const liveCursor = textarea?.selectionStart ?? cursorPosition
const liveValue = textarea?.value ?? code

if (!isPreview && !readOnly) {
setCode(newValue)
emitTagSelection(newValue)
Expand All @@ -547,8 +551,17 @@ export const Code = memo(function Code({
setShowTags(false)
setActiveSourceBlockId(null)

const insertPos = liveValue.slice(0, liveCursor).lastIndexOf('<')
const searchFrom = insertPos !== -1 ? insertPos : liveCursor
const closingBracket = newValue.indexOf('>', searchFrom)
const newCursorPos = closingBracket !== -1 ? closingBracket + 1 : newValue.length
Comment thread
waleedlatif1 marked this conversation as resolved.
Outdated

setTimeout(() => {
editorRef.current?.querySelector('textarea')?.focus()
if (textarea) {
textarea.focus()
textarea.selectionStart = newCursorPos
textarea.selectionEnd = newCursorPos
}
}, 0)
}

Expand All @@ -557,15 +570,28 @@ export const Code = memo(function Code({
* @param newValue - The new code value with the selected env var inserted
*/
const handleEnvVarSelect = (newValue: string) => {
const textarea = editorRef.current?.querySelector('textarea')
const liveCursor = textarea?.selectionStart ?? cursorPosition
const liveValue = textarea?.value ?? code

if (!isPreview && !readOnly) {
setCode(newValue)
emitTagSelection(newValue)
recordChange(newValue)
}
setShowEnvVars(false)

const insertPos = liveValue.slice(0, liveCursor).lastIndexOf('{{')
const searchFrom = insertPos !== -1 ? insertPos : liveCursor
const closingBraces = newValue.indexOf('}}', searchFrom)
const newCursorPos = closingBraces !== -1 ? closingBraces + 2 : newValue.length

setTimeout(() => {
editorRef.current?.querySelector('textarea')?.focus()
if (textarea) {
textarea.focus()
textarea.selectionStart = newCursorPos
textarea.selectionEnd = newCursorPos
}
}, 0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,12 @@ export function ConditionInput({
const handleTagSelectImmediate = (blockId: string, newValue: string) => {
if (isPreview || disabled) return

const textarea = containerRef.current?.querySelector(
`[data-block-id="${blockId}"] textarea`
) as HTMLTextAreaElement | null
Comment thread
waleedlatif1 marked this conversation as resolved.
const liveCursor = textarea?.selectionStart ?? 0
const liveValue = textarea?.value ?? ''
Comment thread
waleedlatif1 marked this conversation as resolved.
Outdated

shouldPersistRef.current = true
setConditionalBlocks((blocks) =>
blocks.map((block) =>
Expand All @@ -582,11 +588,30 @@ export function ConditionInput({
: block
)
emitTagSelection(JSON.stringify(updatedBlocks))

const insertPos = liveValue.slice(0, liveCursor).lastIndexOf('<')
const searchFrom = insertPos !== -1 ? insertPos : liveCursor
const closingBracket = newValue.indexOf('>', searchFrom)
const newCursorPos = closingBracket !== -1 ? closingBracket + 1 : newValue.length

setTimeout(() => {
if (textarea) {
textarea.focus()
textarea.selectionStart = newCursorPos
textarea.selectionEnd = newCursorPos
}
}, 0)
}

const handleEnvVarSelectImmediate = (blockId: string, newValue: string) => {
if (isPreview || disabled) return

const textarea = containerRef.current?.querySelector(
`[data-block-id="${blockId}"] textarea`
) as HTMLTextAreaElement | null
const liveCursor = textarea?.selectionStart ?? 0
const liveValue = textarea?.value ?? ''

shouldPersistRef.current = true
setConditionalBlocks((blocks) =>
blocks.map((block) =>
Expand All @@ -612,6 +637,19 @@ export function ConditionInput({
: block
)
emitTagSelection(JSON.stringify(updatedBlocks))

const insertPos = liveValue.slice(0, liveCursor).lastIndexOf('{{')
const searchFrom = insertPos !== -1 ? insertPos : liveCursor
const closingBraces = newValue.indexOf('}}', searchFrom)
const newCursorPos = closingBraces !== -1 ? closingBraces + 2 : newValue.length

setTimeout(() => {
if (textarea) {
textarea.focus()
textarea.selectionStart = newCursorPos
textarea.selectionEnd = newCursorPos
}
}, 0)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,38 @@ export function useSubflowEditor(currentBlock: BlockState | null, currentBlockId
const handleSubflowTagSelect = useCallback(
(newValue: string) => {
if (!currentBlockId || !isSubflow || !currentBlock) return

const textarea = textareaRef.current
const liveCursor = textarea?.selectionStart ?? cursorPosition
const liveValue = textarea?.value ?? ''
Comment thread
waleedlatif1 marked this conversation as resolved.
Outdated

collaborativeUpdateIterationCollection(
currentBlockId,
currentBlock.type as 'loop' | 'parallel',
newValue
)
setShowTagDropdown(false)

const insertPos = liveValue.slice(0, liveCursor).lastIndexOf('<')
const searchFrom = insertPos !== -1 ? insertPos : liveCursor
const closingBracket = newValue.indexOf('>', searchFrom)
const newCursorPos = closingBracket !== -1 ? closingBracket + 1 : newValue.length

setTimeout(() => {
const textarea = textareaRef.current
if (textarea) {
textarea.focus()
textarea.selectionStart = newCursorPos
textarea.selectionEnd = newCursorPos
}
}, 0)
},
[currentBlockId, isSubflow, currentBlock, collaborativeUpdateIterationCollection]
[
currentBlockId,
isSubflow,
currentBlock,
collaborativeUpdateIterationCollection,
cursorPosition,
]
)
Comment thread
waleedlatif1 marked this conversation as resolved.
Comment thread
waleedlatif1 marked this conversation as resolved.

// Compute derived values
Expand Down