Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selection stuff #4381

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions src/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from 'lib/toolbar'
import { isDesktop } from 'lib/isDesktop'
import { openExternalBrowserIfDesktop } from 'lib/openWindow'
import { convertSelectionsToOld } from 'lib/selections'

export function Toolbar({
className = '',
Expand All @@ -38,12 +39,17 @@ export function Toolbar({
'!border-transparent hover:!border-chalkboard-20 dark:enabled:hover:!border-primary pressed:!border-primary ui-open:!border-primary'

const sketchPathId = useMemo(() => {
if (!isSingleCursorInPipe(context.selectionRanges, kclManager.ast)) {
if (
!isSingleCursorInPipe(
convertSelectionsToOld(context.selectionRanges),
kclManager.ast
)
) {
return false
}
return isCursorInSketchCommandRange(
engineCommandManager.artifactGraph,
context.selectionRanges
convertSelectionsToOld(context.selectionRanges)
)
}, [engineCommandManager.artifactGraph, context.selectionRanges])

Expand Down
6 changes: 4 additions & 2 deletions src/clientSideScene/sceneEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import {
createPipeSubstitution,
findUniqueName,
} from 'lang/modifyAst'
import { Selections, getEventForSegmentSelection } from 'lib/selections'
import { Selections__old, getEventForSegmentSelection } from 'lib/selections'
import { createGridHelper, orthoScale, perspScale } from './helpers'
import { Models } from '@kittycad/lib'
import { uuidv4 } from 'lib/utils'
Expand Down Expand Up @@ -475,7 +475,7 @@ export class SceneEntities {
forward: [number, number, number]
up: [number, number, number]
position?: [number, number, number]
selectionRanges?: Selections
selectionRanges?: Selections__old
}): Promise<{
truncatedAst: Node<Program>
programMemoryOverride: ProgramMemory
Expand Down Expand Up @@ -1291,6 +1291,7 @@ export class SceneEntities {
},
onMove: () => {},
onClick: (args) => {
console.log('onClick', args)
// If there is a valid camera interaction that matches, do that instead
const interaction = sceneInfra.camControls.getInteractionType(
args.mouseEvent
Expand All @@ -1308,6 +1309,7 @@ export class SceneEntities {
}
const { selected } = args
const event = getEventForSegmentSelection(selected)
console.log('event', event)
if (!event) return
sceneInfra.modelingSend(event)
},
Expand Down
22 changes: 18 additions & 4 deletions src/components/AstExplorer.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { useModelingContext } from 'hooks/useModelingContext'
import { editorManager, kclManager } from 'lib/singletons'
import { editorManager, engineCommandManager, kclManager } from 'lib/singletons'
import { getNodeFromPath, getNodePathFromSourceRange } from 'lang/queryAst'
import { useEffect, useRef, useState } from 'react'
import { trap } from 'lib/trap'
import { codeToIdSelections } from 'lib/selections'
import { KclManager } from 'lang/KclSingleton'

Check warning on line 7 in src/components/AstExplorer.tsx

View workflow job for this annotation

GitHub Actions / yarn-lint

'KclManager' is defined but never used

Check warning on line 7 in src/components/AstExplorer.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:ubuntu-latest 1 4

'KclManager' is defined but never used

Check warning on line 7 in src/components/AstExplorer.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:windows-latest 1 4

'KclManager' is defined but never used

Check warning on line 7 in src/components/AstExplorer.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:ubuntu-latest 4 4

'KclManager' is defined but never used

Check warning on line 7 in src/components/AstExplorer.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:ubuntu-latest 3 4

'KclManager' is defined but never used

Check warning on line 7 in src/components/AstExplorer.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:windows-latest 3 4

'KclManager' is defined but never used

Check warning on line 7 in src/components/AstExplorer.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:windows-latest 4 4

'KclManager' is defined but never used

Check warning on line 7 in src/components/AstExplorer.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:ubuntu-latest 2 4

'KclManager' is defined but never used

Check warning on line 7 in src/components/AstExplorer.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:windows-latest 2 4

'KclManager' is defined but never used

export function AstExplorer() {
const { context } = useModelingContext()
const pathToNode = getNodePathFromSourceRange(
// TODO maybe need to have callback to make sure it stays in sync
kclManager.ast,
context.selectionRanges.codeBasedSelections?.[0]?.range
context.selectionRanges.graphSelections?.[0]?.codeRef?.range
)
const [filterKeys, setFilterKeys] = useState<string[]>(['start', 'end'])

Expand Down Expand Up @@ -121,13 +123,25 @@
editorManager.setHighlightRange([[obj?.start || 0, obj.end]])
}}
onClick={(e) => {
const range: [number, number] = [obj?.start || 0, obj.end || 0]
const idInfo = codeToIdSelections([
{
type: 'default',
range,
},
])[0]
const artifact = engineCommandManager.artifactGraph.get(idInfo.id)
if (!artifact) return
send({
type: 'Set selection',
data: {
selectionType: 'singleCodeCursor',
selection: {
type: 'default',
range: [obj?.start || 0, obj.end || 0],
artifact: artifact,
codeRef: {
range,
pathToNode: getNodePathFromSourceRange(kclManager.ast, range),
},
},
},
})
Expand Down
4 changes: 3 additions & 1 deletion src/components/AvailableVarsHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useKclContext } from 'lang/KclProvider'
import { useModelingContext } from 'hooks/useModelingContext'
import { executeAst } from 'lang/langHelpers'
import { trap } from 'lib/trap'
import { convertSelectionsToOld } from 'lib/selections'

export const AvailableVars = ({
onVarClick,
Expand Down Expand Up @@ -96,7 +97,8 @@ export function useCalc({
} {
const { programMemory } = useKclContext()
const { context } = useModelingContext()
const selectionRange = context.selectionRanges.codeBasedSelections[0].range
const selectionRange = convertSelectionsToOld(context.selectionRanges)
.codeBasedSelections[0].range
const inputRef = useRef<HTMLInputElement>(null)
const [availableVarInfo, setAvailableVarInfo] = useState<
ReturnType<typeof findAllPreviousVariables>
Expand Down
6 changes: 4 additions & 2 deletions src/components/CommandBar/CommandBarHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCommandsContext } from 'hooks/useCommandsContext'
import { CustomIcon } from '../CustomIcon'
import React, { useState } from 'react'
import { ActionButton } from '../ActionButton'
import { Selections, getSelectionTypeDisplayText } from 'lib/selections'
import { Selections__old, getSelectionTypeDisplayText } from 'lib/selections'
import { useHotkeys } from 'react-hotkeys-hook'
import { KclCommandValue, KclExpressionWithVariable } from 'lib/commandTypes'
import Tooltip from 'components/Tooltip'
Expand Down Expand Up @@ -125,7 +125,9 @@ function CommandBarHeader({ children }: React.PropsWithChildren<{}>) {
<span data-testid="header-arg-value">
{argValue ? (
arg.inputType === 'selection' ? (
getSelectionTypeDisplayText(argValue as Selections)
getSelectionTypeDisplayText(
argValue as Selections__old
)
) : arg.inputType === 'kcl' ? (
roundOff(
Number(
Expand Down
24 changes: 17 additions & 7 deletions src/components/CommandBar/CommandBarSelectionInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@
import { useKclContext } from 'lang/KclProvider'
import { CommandArgument } from 'lib/commandTypes'
import {
Selection,
Selection__old,
canSubmitSelectionArg,
convertSelectionToOld,

Check warning on line 8 in src/components/CommandBar/CommandBarSelectionInput.tsx

View workflow job for this annotation

GitHub Actions / yarn-lint

'convertSelectionToOld' is defined but never used

Check warning on line 8 in src/components/CommandBar/CommandBarSelectionInput.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:ubuntu-latest 1 4

'convertSelectionToOld' is defined but never used

Check warning on line 8 in src/components/CommandBar/CommandBarSelectionInput.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:windows-latest 1 4

'convertSelectionToOld' is defined but never used

Check warning on line 8 in src/components/CommandBar/CommandBarSelectionInput.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:ubuntu-latest 4 4

'convertSelectionToOld' is defined but never used

Check warning on line 8 in src/components/CommandBar/CommandBarSelectionInput.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:ubuntu-latest 3 4

'convertSelectionToOld' is defined but never used

Check warning on line 8 in src/components/CommandBar/CommandBarSelectionInput.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:windows-latest 3 4

'convertSelectionToOld' is defined but never used

Check warning on line 8 in src/components/CommandBar/CommandBarSelectionInput.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:windows-latest 4 4

'convertSelectionToOld' is defined but never used

Check warning on line 8 in src/components/CommandBar/CommandBarSelectionInput.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:ubuntu-latest 2 4

'convertSelectionToOld' is defined but never used

Check warning on line 8 in src/components/CommandBar/CommandBarSelectionInput.tsx

View workflow job for this annotation

GitHub Actions / playwright:browser:windows-latest 2 4

'convertSelectionToOld' is defined but never used
convertSelectionsToOld,
getSelectionType,
getSelectionTypeDisplayText,
} from 'lib/selections'
import { modelingMachine } from 'machines/modelingMachine'
import { useEffect, useMemo, useRef, useState } from 'react'
import { StateFrom } from 'xstate'

const semanticEntityNames: { [key: string]: Array<Selection['type']> } = {
const semanticEntityNames: { [key: string]: Array<Selection__old['type']> } = {
face: ['extrude-wall', 'start-cap', 'end-cap'],
edge: ['edge', 'line', 'arc'],
point: ['point', 'line-end', 'line-mid'],
}

function getSemanticSelectionType(selectionType: Array<Selection['type']>) {
function getSemanticSelectionType(
selectionType: Array<Selection__old['type']>
) {
const semanticSelectionType = new Set()
selectionType.forEach((type) => {
Object.entries(semanticEntityNames).forEach(([entity, entityTypes]) => {
Expand Down Expand Up @@ -49,10 +53,14 @@
const [hasSubmitted, setHasSubmitted] = useState(false)
const selection = useSelector(arg.machineActor, selectionSelector)
const selectionsByType = useMemo(() => {
const selectionRangeEnd = selection?.codeBasedSelections[0]?.range[1]
return !selectionRangeEnd || selectionRangeEnd === code.length
const selectionRangeEnd = !selection
? null
: convertSelectionsToOld(selection)?.codeBasedSelections[0]?.range[1]
return !selectionRangeEnd || selectionRangeEnd === code.length || !selection
? 'none'
: getSelectionType(selection)
: !selection
? 'none'
: getSelectionType(convertSelectionsToOld(selection))
}, [selection, code])
const canSubmitSelection = useMemo<boolean>(
() => canSubmitSelectionArg(selectionsByType, arg),
Expand Down Expand Up @@ -87,6 +95,8 @@
onSubmit(selection)
}

const selectionOld = selection && convertSelectionsToOld(selection)

return (
<form id="arg-form" onSubmit={handleSubmit}>
<label
Expand All @@ -96,7 +106,7 @@
}
>
{canSubmitSelection
? getSelectionTypeDisplayText(selection) + ' selected'
? getSelectionTypeDisplayText(selectionOld) + ' selected'
: `Please select ${
arg.multiple ? 'one or more ' : 'one '
}${getSemanticSelectionType(arg.selectionTypes).join(' or ')}`}
Expand Down
6 changes: 5 additions & 1 deletion src/components/EngineCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const EngineCommands = () => {
const [engineCommands, clearEngineCommands] = useEngineCommands()
const [containsFilter, setContainsFilter] = useState('')
const [customCmd, setCustomCmd] = useState('')
console.log(JSON.stringify(engineCommands, null, 2))
return (
<div>
<input
Expand Down Expand Up @@ -64,7 +65,10 @@ export const EngineCommands = () => {
)
})}
</div>
<button data-testid="clear-commands" onClick={clearEngineCommands}>
<button
data-testid="clear-commands"
onClick={() => clearEngineCommands()}
>
Clear
</button>
<br />
Expand Down
Loading
Loading