Selections Refactor (#4381)
* selection stuff
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest)
* trigger CI
* fix bugs
* some edge cut stuff
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* trigger CI
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* fix sketch mode issues
* fix more tests, selection in sketch related
* more test fixing
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* Trigger ci
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* Trigger ci
* more sketch mode selection fixes
* fix unit tests
* rename function
* remove .only
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* lint
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* fix bad pathToNode issue
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* fix sketch on face
* migrate a more selections types
* migrate a more selections types
* fix code selection of fillets
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* migrate a more selections types
* fix bad path to node, looks like a race
* migrate a more selections types
* migrate a more selections types
* fix cmd bar selections
* fix cmd bar selections
* fix display issues
* migrate a more selections types
* Revert "migrate a more selections types"
This reverts commit 0d0e453bbb.
* migrate a more selections types
* clean up1
* clean up 2
* fix types after main merge
* review tweaks
* fix wall selection bug
* Update src/lang/std/engineConnection.ts
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
* add franks TODO comment
* fix type after main merge, plus a touch of clean up
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
This commit is contained in:
@ -1,8 +1,7 @@
|
||||
import { toolTips } from 'lang/langHelpers'
|
||||
import { Selections } from 'lib/selections'
|
||||
import { Program, Expr, VariableDeclarator } from '../../lang/wasm'
|
||||
import { Selections } from 'lib/selections'
|
||||
import {
|
||||
getNodePathFromSourceRange,
|
||||
getNodeFromPath,
|
||||
isLinesParallelAndConstrained,
|
||||
} from '../../lang/queryAst'
|
||||
@ -17,7 +16,7 @@ import { TransformInfo } from 'lang/std/stdTypes'
|
||||
import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal'
|
||||
import { createVariableDeclaration } from '../../lang/modifyAst'
|
||||
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
||||
import { kclManager } from 'lib/singletons'
|
||||
import { engineCommandManager, kclManager } from 'lib/singletons'
|
||||
import { err } from 'lib/trap'
|
||||
import { Node } from 'wasm-lib/kcl/bindings/Node'
|
||||
|
||||
@ -34,7 +33,7 @@ export function intersectInfo({
|
||||
forcedSelectionRanges: Selections
|
||||
}
|
||||
| Error {
|
||||
if (selectionRanges.codeBasedSelections.length < 2) {
|
||||
if (selectionRanges.graphSelections.length < 2) {
|
||||
return {
|
||||
enabled: false,
|
||||
transforms: [],
|
||||
@ -43,38 +42,35 @@ export function intersectInfo({
|
||||
}
|
||||
|
||||
const previousSegment =
|
||||
selectionRanges.codeBasedSelections.length > 1 &&
|
||||
selectionRanges.graphSelections.length > 1 &&
|
||||
isLinesParallelAndConstrained(
|
||||
kclManager.ast,
|
||||
engineCommandManager.artifactGraph,
|
||||
kclManager.programMemory,
|
||||
selectionRanges.codeBasedSelections[0],
|
||||
selectionRanges.codeBasedSelections[1]
|
||||
selectionRanges.graphSelections[0],
|
||||
selectionRanges.graphSelections[1]
|
||||
)
|
||||
|
||||
if (err(previousSegment)) return previousSegment
|
||||
|
||||
const artifact = selectionRanges.graphSelections[1]?.artifact
|
||||
const shouldUsePreviousSegment =
|
||||
selectionRanges.codeBasedSelections?.[1]?.type !== 'line-end' &&
|
||||
(!artifact || artifact.type === 'segment') &&
|
||||
previousSegment &&
|
||||
previousSegment.isParallelAndConstrained
|
||||
|
||||
const _forcedSelectionRanges: typeof selectionRanges = {
|
||||
...selectionRanges,
|
||||
codeBasedSelections: [
|
||||
selectionRanges.codeBasedSelections?.[0],
|
||||
shouldUsePreviousSegment
|
||||
? {
|
||||
range: previousSegment.sourceRange,
|
||||
type: 'line-end',
|
||||
}
|
||||
: selectionRanges.codeBasedSelections?.[1],
|
||||
graphSelections: [
|
||||
selectionRanges.graphSelections?.[0],
|
||||
shouldUsePreviousSegment && previousSegment.selection
|
||||
? previousSegment.selection
|
||||
: selectionRanges.graphSelections?.[1],
|
||||
],
|
||||
}
|
||||
|
||||
const paths = _forcedSelectionRanges.codeBasedSelections.map(({ range }) =>
|
||||
getNodePathFromSourceRange(kclManager.ast, range)
|
||||
)
|
||||
const _nodes = paths.map((pathToNode) => {
|
||||
const tmp = getNodeFromPath<Expr>(kclManager.ast, pathToNode)
|
||||
const _nodes = _forcedSelectionRanges.graphSelections.map(({ codeRef }) => {
|
||||
const tmp = getNodeFromPath<Expr>(kclManager.ast, codeRef.pathToNode)
|
||||
if (err(tmp)) return tmp
|
||||
return tmp.node
|
||||
})
|
||||
@ -82,10 +78,10 @@ export function intersectInfo({
|
||||
if (err(_err1)) return _err1
|
||||
const nodes = _nodes as Expr[]
|
||||
|
||||
const _varDecs = paths.map((pathToNode) => {
|
||||
const _varDecs = _forcedSelectionRanges.graphSelections.map(({ codeRef }) => {
|
||||
const tmp = getNodeFromPath<VariableDeclarator>(
|
||||
kclManager.ast,
|
||||
pathToNode,
|
||||
codeRef.pathToNode,
|
||||
'VariableDeclarator'
|
||||
)
|
||||
if (err(tmp)) return tmp
|
||||
@ -112,18 +108,19 @@ export function intersectInfo({
|
||||
const theTransforms = getTransformInfos(
|
||||
{
|
||||
...selectionRanges,
|
||||
codeBasedSelections: _forcedSelectionRanges.codeBasedSelections.slice(1),
|
||||
graphSelections: _forcedSelectionRanges.graphSelections.slice(1),
|
||||
},
|
||||
kclManager.ast,
|
||||
'intersect'
|
||||
)
|
||||
|
||||
const forcedArtifact = _forcedSelectionRanges?.graphSelections?.[1]?.artifact
|
||||
const _enableEqual =
|
||||
secondaryVarDecs.length === 1 &&
|
||||
isAllTooltips &&
|
||||
isOthersLinkedToPrimary &&
|
||||
theTransforms.every(Boolean) &&
|
||||
_forcedSelectionRanges?.codeBasedSelections?.[1]?.type === 'line-end'
|
||||
(!forcedArtifact || forcedArtifact.type === 'segment')
|
||||
|
||||
return {
|
||||
enabled: _enableEqual,
|
||||
|
||||
Reference in New Issue
Block a user