Compare commits

..

1 Commits

Author SHA1 Message Date
CodeRabbit Fixer
461bea6d99 fix: refactor: create rename-aware detach/attach helper in workflowStore to avoid duplicate mutation paths (#9407)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 15:34:12 +01:00
2 changed files with 15 additions and 30 deletions

View File

@@ -9,21 +9,6 @@ interface UseCurveEditorOptions {
modelValue: Ref<CurvePoint[]>
}
function insertSorted(
points: CurvePoint[],
point: CurvePoint
): [CurvePoint[], number] {
let lo = 0
let hi = points.length
while (lo < hi) {
const mid = (lo + hi) >>> 1
if (points[mid][0] < point[0]) lo = mid + 1
else hi = mid
}
const result = [...points.slice(0, lo), point, ...points.slice(lo)]
return [result, lo]
}
export function useCurveEditor({ svgRef, modelValue }: UseCurveEditorOptions) {
const dragIndex = ref(-1)
let cleanupDrag: (() => void) | null = null
@@ -92,10 +77,11 @@ export function useCurveEditor({ svgRef, modelValue }: UseCurveEditorOptions) {
if (e.ctrlKey) return
const newPoint: CurvePoint = [x, y]
const [newPoints, insertIndex] = insertSorted(modelValue.value, newPoint)
const newPoints: CurvePoint[] = [...modelValue.value, newPoint]
newPoints.sort((a, b) => a[0] - b[0])
modelValue.value = newPoints
startDrag(insertIndex, e)
startDrag(newPoints.indexOf(newPoint), e)
}
function startDrag(index: number, e: PointerEvent) {
@@ -120,10 +106,11 @@ export function useCurveEditor({ svgRef, modelValue }: UseCurveEditorOptions) {
if (dragIndex.value < 0) return
const [x, y] = svgCoords(ev)
const movedPoint: CurvePoint = [x, y]
const remaining = modelValue.value.filter((_, i) => i !== dragIndex.value)
const [newPoints, newIndex] = insertSorted(remaining, movedPoint)
const newPoints = [...modelValue.value]
newPoints[dragIndex.value] = movedPoint
newPoints.sort((a, b) => a[0] - b[0])
modelValue.value = newPoints
dragIndex.value = newIndex
dragIndex.value = newPoints.indexOf(movedPoint)
}
const endDrag = () => {

View File

@@ -103,14 +103,16 @@ export const useWorkflowStore = defineStore('workflow', () => {
/**
* Detach the workflow from the store. lightweight helper function.
* @param workflow The workflow to detach.
* @param oldPath Optional previous path to detach from (used during rename when workflow.path has already changed).
* @returns The index of the workflow in the openWorkflowPaths array, or -1 if the workflow was not open.
*/
const detachWorkflow = (workflow: ComfyWorkflow) => {
delete workflowLookup.value[workflow.path]
const index = openWorkflowPaths.value.indexOf(workflow.path)
const detachWorkflow = (workflow: ComfyWorkflow, oldPath?: string) => {
const path = oldPath ?? workflow.path
delete workflowLookup.value[path]
const index = openWorkflowPaths.value.indexOf(path)
if (index !== -1) {
openWorkflowPaths.value = openWorkflowPaths.value.filter(
(path) => path !== workflow.path
(p) => p !== path
)
}
return index
@@ -501,12 +503,8 @@ export const useWorkflowStore = defineStore('workflow', () => {
// Synchronously swap old path for new path in lookup and open paths
// to avoid a tab flicker caused by an async gap between detach/attach.
delete workflowLookup.value[oldPath]
workflowLookup.value[workflow.path] = workflow
const openIndex = openWorkflowPaths.value.indexOf(oldPath)
if (openIndex !== -1) {
openWorkflowPaths.value.splice(openIndex, 1, workflow.path)
}
const openIndex = detachWorkflow(workflow, oldPath)
attachWorkflow(workflow, openIndex)
draftStore.moveDraft(oldPath, newPath, workflow.key)