* handle if graphSelections is empty * fix removeConstrainingValuesInfo by using pathToNodes if available instead of selectionRanges: current selection should not be required to remove constraints * selectionRanges not needed for removeConstrainingValuesInfo anymore * fix remove constraint unit test: pass line's pathToNode instead of argument to remove constraint
This commit is contained in:
@ -15,21 +15,15 @@ import type { Selection, Selections } from '@src/lib/selections'
|
|||||||
import { kclManager } from '@src/lib/singletons'
|
import { kclManager } from '@src/lib/singletons'
|
||||||
import { err } from '@src/lib/trap'
|
import { err } from '@src/lib/trap'
|
||||||
|
|
||||||
export function removeConstrainingValuesInfo({
|
export function removeConstrainingValuesInfo(pathToNodes: Array<PathToNode>):
|
||||||
selectionRanges,
|
|
||||||
pathToNodes,
|
|
||||||
}: {
|
|
||||||
selectionRanges: Selections
|
|
||||||
pathToNodes?: Array<PathToNode>
|
|
||||||
}):
|
|
||||||
| {
|
| {
|
||||||
transforms: TransformInfo[]
|
transforms: TransformInfo[]
|
||||||
enabled: boolean
|
enabled: boolean
|
||||||
updatedSelectionRanges: Selections
|
updatedSelectionRanges: Selections
|
||||||
}
|
}
|
||||||
| Error {
|
| Error {
|
||||||
const _nodes = selectionRanges.graphSelections.map(({ codeRef }) => {
|
const _nodes = pathToNodes.map((pathToNode) => {
|
||||||
const tmp = getNodeFromPath<Expr>(kclManager.ast, codeRef.pathToNode)
|
const tmp = getNodeFromPath<Expr>(kclManager.ast, pathToNode)
|
||||||
if (tmp instanceof Error) return tmp
|
if (tmp instanceof Error) return tmp
|
||||||
return tmp.node
|
return tmp.node
|
||||||
})
|
})
|
||||||
@ -37,19 +31,17 @@ export function removeConstrainingValuesInfo({
|
|||||||
if (err(_err1)) return _err1
|
if (err(_err1)) return _err1
|
||||||
const nodes = _nodes as Expr[]
|
const nodes = _nodes as Expr[]
|
||||||
|
|
||||||
const updatedSelectionRanges = pathToNodes
|
const updatedSelectionRanges = {
|
||||||
? {
|
otherSelections: [],
|
||||||
otherSelections: [],
|
graphSelections: nodes.map(
|
||||||
graphSelections: nodes.map(
|
(node): Selection => ({
|
||||||
(node): Selection => ({
|
codeRef: codeRefFromRange(
|
||||||
codeRef: codeRefFromRange(
|
topLevelRange(node.start, node.end),
|
||||||
topLevelRange(node.start, node.end),
|
kclManager.ast
|
||||||
kclManager.ast
|
|
||||||
),
|
|
||||||
})
|
|
||||||
),
|
),
|
||||||
}
|
})
|
||||||
: selectionRanges
|
),
|
||||||
|
}
|
||||||
const isAllTooltips = nodes.every(
|
const isAllTooltips = nodes.every(
|
||||||
(node) =>
|
(node) =>
|
||||||
node?.type === 'CallExpressionKw' &&
|
node?.type === 'CallExpressionKw' &&
|
||||||
@ -78,10 +70,12 @@ export function applyRemoveConstrainingValues({
|
|||||||
pathToNodeMap: PathToNodeMap
|
pathToNodeMap: PathToNodeMap
|
||||||
}
|
}
|
||||||
| Error {
|
| Error {
|
||||||
const constraint = removeConstrainingValuesInfo({
|
pathToNodes =
|
||||||
selectionRanges,
|
pathToNodes ||
|
||||||
pathToNodes,
|
selectionRanges.graphSelections.map(({ codeRef }) => {
|
||||||
})
|
return codeRef.pathToNode
|
||||||
|
})
|
||||||
|
const constraint = removeConstrainingValuesInfo(pathToNodes)
|
||||||
if (err(constraint)) return constraint
|
if (err(constraint)) return constraint
|
||||||
const { transforms, updatedSelectionRanges } = constraint
|
const { transforms, updatedSelectionRanges } = constraint
|
||||||
|
|
||||||
|
@ -333,6 +333,15 @@ export default class EditorManager {
|
|||||||
|
|
||||||
createEditorSelection(selections: Selections) {
|
createEditorSelection(selections: Selections) {
|
||||||
let codeBasedSelections = []
|
let codeBasedSelections = []
|
||||||
|
|
||||||
|
// Handle empty graphSelections array to avoid runtime errors
|
||||||
|
if (selections.graphSelections.length === 0) {
|
||||||
|
const defaultCursor = EditorSelection.cursor(
|
||||||
|
this._editorView?.state.doc.length || 0
|
||||||
|
)
|
||||||
|
return EditorSelection.create([defaultCursor], 0)
|
||||||
|
}
|
||||||
|
|
||||||
for (const selection of selections.graphSelections) {
|
for (const selection of selections.graphSelections) {
|
||||||
const safeEnd = Math.min(
|
const safeEnd = Math.min(
|
||||||
selection.codeRef.range[1],
|
selection.codeRef.range[1],
|
||||||
|
@ -1252,18 +1252,11 @@ p3 = [342.51, 216.38],
|
|||||||
if (err(callExp)) {
|
if (err(callExp)) {
|
||||||
throw new Error('Failed to get CallExpressionKw node')
|
throw new Error('Failed to get CallExpressionKw node')
|
||||||
}
|
}
|
||||||
const constraintInfo = getConstraintInfoKw(
|
|
||||||
callExp.node,
|
|
||||||
codeManager.code,
|
|
||||||
artifact.codeRef.pathToNode,
|
|
||||||
filter
|
|
||||||
)
|
|
||||||
const constraint = constraintInfo[constraintIndex]
|
|
||||||
|
|
||||||
// Now that we're in sketchIdle state, test the "Constrain with named value" event
|
// Now that we're in sketchIdle state, test the "Constrain with named value" event
|
||||||
actor.send({
|
actor.send({
|
||||||
type: 'Constrain remove constraints',
|
type: 'Constrain remove constraints',
|
||||||
data: constraint.pathToNode,
|
data: artifact.codeRef.pathToNode,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Wait for the state to change in response to the constraint
|
// Wait for the state to change in response to the constraint
|
||||||
|
@ -752,10 +752,13 @@ export const modelingMachine = setup({
|
|||||||
event,
|
event,
|
||||||
}) => {
|
}) => {
|
||||||
if (event.type !== 'Constrain remove constraints') return false
|
if (event.type !== 'Constrain remove constraints') return false
|
||||||
const info = removeConstrainingValuesInfo({
|
|
||||||
selectionRanges,
|
const pathToNodes = event.data
|
||||||
pathToNodes: event.data && [event.data],
|
? [event.data]
|
||||||
})
|
: selectionRanges.graphSelections.map(({ codeRef }) => {
|
||||||
|
return codeRef.pathToNode
|
||||||
|
})
|
||||||
|
const info = removeConstrainingValuesInfo(pathToNodes)
|
||||||
if (err(info)) return false
|
if (err(info)) return false
|
||||||
return info.enabled
|
return info.enabled
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user