Replace number command bar arg input type with kcl expression input (#1474)
* Rename useCalc * Move CommandBar so it has access to settings and kcl * Create codemirror variable mention extension * Make project path a dep of TextEditor useMemo * Add incomplete KCL input for CommandBar to replace current number arg type * Add previous variables autocompletion to kcl input * Fix missed typos from merge * Working AST mods, not working variable additions * Add ability to create a new variable * Add icon and tooltip to command arg tag if a variable is added * Polish variable naming logic, preserve when going back * Allow stepping back from KCL input * Don't prevent keydown of enter, it's used by autocomplete * Round the variable value in cmd bar header * Add Playwright test * Formatting, polish TS types * More type wrangling * Needed to fmt after above type wrangling * Update snapshot tests to account for new variable name autogeneration * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * Merge branch 'main' into cmd-bar-make-variable * Update all test instances of var name with number index after merge with main * Partial revert of "Polish variable naming logic, preserve when going back" This reverts commitdddcb13c36
. * Revert "Update all test instances of var name with number index after merge with main" This reverts commit8c4b63b523
. * Revert "Update snapshot tests to account for new variable name autogeneration" This reverts commit11bfce3832
. * Retry a refactoring of findUniqueName * minor feedback from @jgomez720 - better highlighting of kcl input - consistent hotkeys - disallow invalid var names * Polish stepping back state logic * Fix tests now that keyboard shortcut changed * Remove unused imports * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * Fix tests * Trigger CI * Update src/components/ProjectSidebarMenu.test.tsx * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * re-trigger CI --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
This commit is contained in:
@ -162,18 +162,32 @@ export function findUniqueName(
|
||||
pad = 3,
|
||||
index = 1
|
||||
): string {
|
||||
let searchStr = ''
|
||||
if (typeof ast === 'string') {
|
||||
searchStr = ast
|
||||
} else {
|
||||
searchStr = JSON.stringify(ast)
|
||||
let searchStr: string = typeof ast === 'string' ? ast : JSON.stringify(ast)
|
||||
const indexStr = String(index).padStart(pad, '0')
|
||||
|
||||
const endingDigitsMatcher = /\d+$/
|
||||
const nameEndsInDigits = name.match(endingDigitsMatcher)
|
||||
let nameIsInString = searchStr.includes(`:"${name}"`)
|
||||
|
||||
if (nameEndsInDigits !== null) {
|
||||
// base case: name is unique and ends in digits
|
||||
if (!nameIsInString) return name
|
||||
|
||||
// recursive case: name is not unique and ends in digits
|
||||
const newPad = nameEndsInDigits[1].length
|
||||
const newIndex = parseInt(nameEndsInDigits[1]) + 1
|
||||
const nameWithoutDigits = name.replace(endingDigitsMatcher, '')
|
||||
|
||||
return findUniqueName(searchStr, nameWithoutDigits, newPad, newIndex)
|
||||
}
|
||||
const indexStr = `${index}`.padStart(pad, '0')
|
||||
|
||||
const newName = `${name}${indexStr}`
|
||||
const isInString = searchStr.includes(newName)
|
||||
if (!isInString) {
|
||||
return newName
|
||||
}
|
||||
nameIsInString = searchStr.includes(`:"${newName}"`)
|
||||
|
||||
// base case: name is unique and does not end in digits
|
||||
if (!nameIsInString) return newName
|
||||
|
||||
// recursive case: name is not unique and does not end in digits
|
||||
return findUniqueName(searchStr, name, pad, index + 1)
|
||||
}
|
||||
|
||||
@ -273,7 +287,7 @@ export function extrudeSketch(
|
||||
node: Program,
|
||||
pathToNode: PathToNode,
|
||||
shouldPipe = true,
|
||||
distance = 4
|
||||
distance = createLiteral(4) as Value
|
||||
): {
|
||||
modifiedAst: Program
|
||||
pathToNode: PathToNode
|
||||
@ -299,7 +313,7 @@ export function extrudeSketch(
|
||||
getNodeFromPath<VariableDeclarator>(_node, pathToNode, 'VariableDeclarator')
|
||||
|
||||
const extrudeCall = createCallExpressionStdLib('extrude', [
|
||||
createLiteral(distance),
|
||||
distance,
|
||||
shouldPipe
|
||||
? createPipeSubstitution()
|
||||
: {
|
||||
|
Reference in New Issue
Block a user