Fix move only working first time (#850)
* nuke fixIdMappings * update readme * remove sourceRangeMap as it was redundant repeated state already covered by the artifactMap * bug fix, name conflict * bug fix * update artifact map when sketch is first created * update artifact map for line generation too * fmt * update move state to allow selections * allow for selection of vertices some what hacky, but better than nothing * unnecessary react hook dependency * generic react linting * move working for non-execute case * block partial contrained things too for now
This commit is contained in:
@ -2,13 +2,14 @@ import { useEffect } from 'react'
|
||||
import { useStore } from 'useStore'
|
||||
import { engineCommandManager } from '../lang/std/engineConnection'
|
||||
import { useModelingContext } from './useModelingContext'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
export function useEngineConnectionSubscriptions() {
|
||||
const { setHighlightRange, highlightRange } = useStore((s) => ({
|
||||
setHighlightRange: s.setHighlightRange,
|
||||
highlightRange: s.highlightRange,
|
||||
}))
|
||||
const { send } = useModelingContext()
|
||||
const { send, context } = useModelingContext()
|
||||
useEffect(() => {
|
||||
if (!engineCommandManager) return
|
||||
|
||||
@ -17,7 +18,7 @@ export function useEngineConnectionSubscriptions() {
|
||||
callback: ({ data }) => {
|
||||
if (data?.entity_id) {
|
||||
const sourceRange =
|
||||
engineCommandManager.sourceRangeMap[data.entity_id]
|
||||
engineCommandManager.artifactMap?.[data.entity_id]?.range
|
||||
setHighlightRange(sourceRange)
|
||||
} else if (
|
||||
!highlightRange ||
|
||||
@ -37,19 +38,58 @@ export function useEngineConnectionSubscriptions() {
|
||||
})
|
||||
return
|
||||
}
|
||||
const sourceRange = engineCommandManager.sourceRangeMap[data.entity_id]
|
||||
send({
|
||||
type: 'Set selection',
|
||||
data: {
|
||||
selectionType: 'singleCodeCursor',
|
||||
selection: { range: sourceRange, type: 'default' },
|
||||
},
|
||||
})
|
||||
const sourceRange =
|
||||
engineCommandManager.artifactMap[data.entity_id]?.range
|
||||
if (engineCommandManager.artifactMap[data.entity_id]) {
|
||||
send({
|
||||
type: 'Set selection',
|
||||
data: {
|
||||
selectionType: 'singleCodeCursor',
|
||||
selection: { range: sourceRange, type: 'default' },
|
||||
},
|
||||
})
|
||||
} else {
|
||||
// selected a vertex
|
||||
engineCommandManager
|
||||
.sendSceneCommand({
|
||||
type: 'modeling_cmd_req',
|
||||
cmd_id: uuidv4(),
|
||||
cmd: {
|
||||
type: 'path_get_curve_uuids_for_vertices',
|
||||
vertex_ids: [data.entity_id],
|
||||
path_id: context.sketchEnginePathId,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
const curveIds = res?.data?.data?.curve_ids
|
||||
const ranges = curveIds
|
||||
.map(
|
||||
(id: string) => engineCommandManager.artifactMap[id]?.range
|
||||
)
|
||||
.sort((a: [number, number], b: [number, number]) => a[0] - b[0])
|
||||
// default to the head of the curve selected
|
||||
const _sourceRange = ranges?.[0]
|
||||
// TODO, we telling the engine that the line is selected, becasue we don't store
|
||||
// vertex ranges in the artifact map, needs some thought.
|
||||
send({
|
||||
type: 'Set selection',
|
||||
data: {
|
||||
selectionType: 'singleCodeCursor',
|
||||
selection: { range: _sourceRange, type: 'line-end' },
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
return () => {
|
||||
unSubHover()
|
||||
unSubClick()
|
||||
}
|
||||
}, [engineCommandManager, setHighlightRange, highlightRange])
|
||||
}, [
|
||||
engineCommandManager,
|
||||
setHighlightRange,
|
||||
highlightRange,
|
||||
context.sketchEnginePathId,
|
||||
])
|
||||
}
|
||||
|
Reference in New Issue
Block a user