zoom to fit on between projects tauri fix (#2504)

* fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* triiger

* make better

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)

* empty

* fix tests

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Jess Frazelle
2024-05-24 12:32:15 -07:00
committed by GitHub
parent 1db3e1b5e4
commit 4cb6ceb043
12 changed files with 79 additions and 53 deletions

View File

@ -1696,7 +1696,11 @@ test('Hovering over 3d features highlights code', async ({ page }) => {
await page.goto('/') await page.goto('/')
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
await page.waitForTimeout(100) // wait for execution done
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
await u.openAndClearDebugPanel() await u.openAndClearDebugPanel()
await u.sendCustomCmd({ await u.sendCustomCmd({
type: 'modeling_cmd_req', type: 'modeling_cmd_req',
@ -1853,7 +1857,7 @@ fn yohey = (pos) => {
await page.getByText(selectionsSnippets.extrudeAndEditAllowed).click() await page.getByText(selectionsSnippets.extrudeAndEditAllowed).click()
await page.getByRole('button', { name: 'Start Sketch' }).click() await page.getByRole('button', { name: 'Start Sketch' }).click()
await page.getByTestId('KCL Code').click() await page.getByTestId('KCL Code').click()
await page.mouse.click(300, 500) await page.mouse.click(734, 134)
await page.getByTestId('KCL Code').click() await page.getByTestId('KCL Code').click()
// expect main content to contain `part005` i.e. started a new sketch // expect main content to contain `part005` i.e. started a new sketch
await expect(page.locator('.cm-content')).toHaveText( await expect(page.locator('.cm-content')).toHaveText(
@ -2218,6 +2222,12 @@ test('Sketch on face', async ({ page }) => {
await page.setViewportSize({ width: 1200, height: 500 }) await page.setViewportSize({ width: 1200, height: 500 })
await page.goto('/') await page.goto('/')
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
// wait for execution done
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
await expect( await expect(
page.getByRole('button', { name: 'Start Sketch' }) page.getByRole('button', { name: 'Start Sketch' })
).not.toBeDisabled() ).not.toBeDisabled()
@ -2260,9 +2270,9 @@ test('Sketch on face', async ({ page }) => {
await expect(page.locator('.cm-content')) await expect(page.locator('.cm-content'))
.toContainText(`const part002 = startSketchOn(part001, 'seg01') .toContainText(`const part002 = startSketchOn(part001, 'seg01')
|> startProfileAt([-13.02, 6.52], %) |> startProfileAt([-12.94, 6.6], %)
|> line([2.1, -0.18], %) |> line([2.45, -0.2], %)
|> line([-2.23, -1.07], %) |> line([-2.6, -1.25], %)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)`) |> close(%)`)
@ -2273,7 +2283,7 @@ test('Sketch on face', async ({ page }) => {
await u.updateCamPosition([1049, 239, 686]) await u.updateCamPosition([1049, 239, 686])
await u.closeDebugPanel() await u.closeDebugPanel()
await page.getByText('startProfileAt([-13.02, 6.52], %)').click() await page.getByText('startProfileAt([-12.94, 6.6], %)').click()
await expect(page.getByRole('button', { name: 'Edit Sketch' })).toBeVisible() await expect(page.getByRole('button', { name: 'Edit Sketch' })).toBeVisible()
await u.doAndWaitForCmd( await u.doAndWaitForCmd(
() => page.getByRole('button', { name: 'Edit Sketch' }).click(), () => page.getByRole('button', { name: 'Edit Sketch' }).click(),
@ -2312,7 +2322,7 @@ test('Sketch on face', async ({ page }) => {
await page.getByRole('button', { name: 'Exit Sketch' }).click() await page.getByRole('button', { name: 'Exit Sketch' }).click()
await u.expectCmdLog('[data-message-type="execution-done"]') await u.expectCmdLog('[data-message-type="execution-done"]')
await page.getByText('startProfileAt([-13.02, 6.52], %)').click() await page.getByText('startProfileAt([-12.94, 6.6], %)').click()
await expect(page.getByRole('button', { name: 'Extrude' })).not.toBeDisabled() await expect(page.getByRole('button', { name: 'Extrude' })).not.toBeDisabled()
await page.waitForTimeout(100) await page.waitForTimeout(100)
@ -2349,6 +2359,7 @@ test('Can code mod a line length', async ({ page }) => {
await page.setViewportSize({ width: 1200, height: 500 }) await page.setViewportSize({ width: 1200, height: 500 })
await page.goto('/') await page.goto('/')
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
await u.openDebugPanel() await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]') await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel() await u.closeDebugPanel()
@ -2408,6 +2419,7 @@ test('Extrude from command bar selects extrude line after', async ({
await page.setViewportSize({ width: 1200, height: 500 }) await page.setViewportSize({ width: 1200, height: 500 })
await page.goto('/') await page.goto('/')
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
await u.openDebugPanel() await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]') await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel() await u.closeDebugPanel()
@ -2599,7 +2611,11 @@ test.describe('Testing segment overlays', () => {
await page.goto('/') await page.goto('/')
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
await page.waitForTimeout(1000) // wait for execution done
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
await u.openAndClearDebugPanel() await u.openAndClearDebugPanel()
await u.sendCustomCmd({ await u.sendCustomCmd({
type: 'modeling_cmd_req', type: 'modeling_cmd_req',
@ -2741,6 +2757,11 @@ const part001 = startSketchOn('XZ')
await page.goto('/') await page.goto('/')
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
// wait for execution done
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
await page.getByText('xLine(26.04, %)').click() await page.getByText('xLine(26.04, %)').click()
await page.waitForTimeout(100) await page.waitForTimeout(100)
await page.getByRole('button', { name: 'Edit Sketch' }).click() await page.getByRole('button', { name: 'Edit Sketch' }).click()
@ -2813,6 +2834,11 @@ const part001 = startSketchOn('XZ')
await page.goto('/') await page.goto('/')
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
// wait for execution done
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
await page.getByText('xLineTo(9 - 5, %)').click() await page.getByText('xLineTo(9 - 5, %)').click()
await page.waitForTimeout(100) await page.waitForTimeout(100)
await page.getByRole('button', { name: 'Edit Sketch' }).click() await page.getByRole('button', { name: 'Edit Sketch' }).click()
@ -2922,6 +2948,11 @@ const part001 = startSketchOn('XZ')
await page.goto('/') await page.goto('/')
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
// wait for execution done
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
await page.getByText('xLineTo(9 - 5, %)').click() await page.getByText('xLineTo(9 - 5, %)').click()
await page.waitForTimeout(100) await page.waitForTimeout(100)
await page.getByRole('button', { name: 'Edit Sketch' }).click() await page.getByRole('button', { name: 'Edit Sketch' }).click()
@ -3059,6 +3090,11 @@ const part001 = startSketchOn('XZ')
await page.goto('/') await page.goto('/')
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
// wait for execution done
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
await page.getByText('xLineTo(9 - 5, %)').click() await page.getByText('xLineTo(9 - 5, %)').click()
await page.waitForTimeout(100) await page.waitForTimeout(100)
await page.getByRole('button', { name: 'Edit Sketch' }).click() await page.getByRole('button', { name: 'Edit Sketch' }).click()
@ -3158,6 +3194,11 @@ const part001 = startSketchOn('XZ')
await page.goto('/') await page.goto('/')
await u.waitForAuthSkipAppStart() await u.waitForAuthSkipAppStart()
// wait for execution done
await u.openDebugPanel()
await u.expectCmdLog('[data-message-type="execution-done"]')
await u.closeDebugPanel()
await page.getByText('xLineTo(9 - 5, %)').click() await page.getByText('xLineTo(9 - 5, %)').click()
await page.waitForTimeout(100) await page.waitForTimeout(100)
await page.getByRole('button', { name: 'Edit Sketch' }).click() await page.getByRole('button', { name: 'Edit Sketch' }).click()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 75 KiB

View File

@ -172,7 +172,7 @@ const FileTreeItem = ({
codeManager.code codeManager.code
) )
codeManager.writeToFile() codeManager.writeToFile()
kclManager.executeCode(true) kclManager.executeCode(true, true)
} else { } else {
// Let the lsp servers know we closed a file. // Let the lsp servers know we closed a file.
onFileClose(currentFile?.path || null, project?.path || null) onFileClose(currentFile?.path || null, project?.path || null)

View File

@ -66,7 +66,7 @@ export const KclEditorPane = () => {
useEffect(() => { useEffect(() => {
if (typeof window === 'undefined') return if (typeof window === 'undefined') return
const onlineCallback = () => kclManager.executeCode(true) const onlineCallback = () => kclManager.executeCode(true, true)
window.addEventListener('online', onlineCallback) window.addEventListener('online', onlineCallback)
return () => window.removeEventListener('online', onlineCallback) return () => window.removeEventListener('online', onlineCallback)
}, []) }, [])

View File

@ -170,7 +170,7 @@ export const SettingsAuthProviderBase = ({
id: `${event.type}.success`, id: `${event.type}.success`,
}) })
}, },
'Execute AST': () => kclManager.executeCode(true), 'Execute AST': () => kclManager.executeCode(true, true),
persistSettings: (context) => persistSettings: (context) =>
saveSettings(context, loadedProject?.project?.path), saveSettings(context, loadedProject?.project?.path),
}, },

View File

@ -59,7 +59,7 @@ export function useSetupEngineManager(
executeCode: () => { executeCode: () => {
// We only want to execute the code here that we already have set. // We only want to execute the code here that we already have set.
// Nothing else. // Nothing else.
return kclManager.executeCode(true) return kclManager.executeCode(true, true)
}, },
token, token,
settings, settings,

View File

@ -176,7 +176,11 @@ export class KclManager {
// This NEVER updates the code, if you want to update the code DO NOT add to // This NEVER updates the code, if you want to update the code DO NOT add to
// this function, too many other things that don't want it exist. // this function, too many other things that don't want it exist.
// just call to codeManager from wherever you want in other files. // just call to codeManager from wherever you want in other files.
async executeAst(ast: Program = this._ast, executionId?: number) { async executeAst(
ast: Program = this._ast,
zoomToFit?: boolean,
executionId?: number
): Promise<void> {
await this?.engineCommandManager?.waitForReady await this?.engineCommandManager?.waitForReady
const currentExecutionId = executionId || Date.now() const currentExecutionId = executionId || Date.now()
this._cancelTokens.set(currentExecutionId, false) this._cancelTokens.set(currentExecutionId, false)
@ -189,6 +193,19 @@ export class KclManager {
}) })
sceneInfra.modelingSend({ type: 'code edit during sketch' }) sceneInfra.modelingSend({ type: 'code edit during sketch' })
defaultSelectionFilter(programMemory, this.engineCommandManager) defaultSelectionFilter(programMemory, this.engineCommandManager)
if (zoomToFit) {
await this.engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: {
type: 'zoom_to_fit',
object_ids: [], // leave empty to zoom to all objects
padding: 0.1, // padding around the objects
},
})
}
this.isExecuting = false this.isExecuting = false
// Check the cancellation token for this execution before applying side effects // Check the cancellation token for this execution before applying side effects
if (this._cancelTokens.get(currentExecutionId)) { if (this._cancelTokens.get(currentExecutionId)) {
@ -259,14 +276,14 @@ export class KclManager {
this._cancelTokens.set(key, true) this._cancelTokens.set(key, true)
}) })
} }
executeCode(force?: boolean) { async executeCode(force?: boolean, zoomToFit?: boolean): Promise<void> {
// If we want to force it we don't want to defer it. // If we want to force it we don't want to defer it.
if (!force) return this._defferer(codeManager.code) if (!force) return this._defferer(codeManager.code)
const ast = this.safeParse(codeManager.code) const ast = this.safeParse(codeManager.code)
if (!ast) return if (!ast) return
this.ast = { ...ast } this.ast = { ...ast }
return this.executeAst(ast) return this.executeAst(ast, zoomToFit)
} }
format() { format() {
const originalCode = codeManager.code const originalCode = codeManager.code

View File

@ -1136,22 +1136,6 @@ export class EngineCommandManager {
this.resolveReady() this.resolveReady()
setIsStreamReady(true) setIsStreamReady(true)
await executeCode() await executeCode()
await this.sendSceneCommand({
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: {
type: 'zoom_to_fit',
object_ids: [], // leave empty to zoom to all objects
padding: 0.1, // padding around the objects
},
})
// make sure client camera syncs after zoom to fit since zoom to fit doesn't return camera settings
// TODO: https://github.com/KittyCAD/engine/issues/2098
await this.sendSceneCommand({
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: { type: 'default_camera_get_settings' },
})
}) })
}, },
onClose: () => { onClose: () => {

View File

@ -12,7 +12,7 @@ import { loadAndValidateSettings } from './settings/settingsUtils'
import makeUrlPathRelative from './makeUrlPathRelative' import makeUrlPathRelative from './makeUrlPathRelative'
import { sep } from '@tauri-apps/api/path' import { sep } from '@tauri-apps/api/path'
import { readTextFile } from '@tauri-apps/plugin-fs' import { readTextFile } from '@tauri-apps/plugin-fs'
import { codeManager, engineCommandManager, kclManager } from 'lib/singletons' import { codeManager, kclManager } from 'lib/singletons'
import { fileSystemManager } from 'lang/std/fileSystemManager' import { fileSystemManager } from 'lang/std/fileSystemManager'
import { import {
getProjectInfo, getProjectInfo,
@ -20,7 +20,6 @@ import {
listProjects, listProjects,
} from './tauri' } from './tauri'
import { createSettings } from './settings/initialSettings' import { createSettings } from './settings/initialSettings'
import { uuidv4 } from './utils'
// The root loader simply resolves the settings and any errors that // The root loader simply resolves the settings and any errors that
// occurred during the settings load // occurred during the settings load
@ -105,23 +104,8 @@ export const fileLoader: LoaderFunction = async ({
// the file system and not the editor. // the file system and not the editor.
codeManager.updateCurrentFilePath(current_file_path) codeManager.updateCurrentFilePath(current_file_path)
codeManager.updateCodeStateEditor(code) codeManager.updateCodeStateEditor(code)
kclManager.executeCode(true) // We don't want to call await on execute code since we don't want to block the UI
await engineCommandManager.sendSceneCommand({ kclManager.executeCode(true, true)
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: {
type: 'zoom_to_fit',
object_ids: [], // leave empty to zoom to all objects
padding: 0.1, // padding around the objects
},
})
// make sure client camera syncs after zoom to fit since zoom to fit doesn't return camera settings
// TODO: https://github.com/KittyCAD/engine/issues/2098
await engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: { type: 'default_camera_get_settings' },
})
// Set the file system manager to the project path // Set the file system manager to the project path
// So that WASM gets an updated path for operations // So that WASM gets an updated path for operations

View File

@ -15,7 +15,7 @@ export default function FutureWork() {
codeManager.updateCodeEditor(bracket) codeManager.updateCodeEditor(bracket)
if (kclManager.engineCommandManager.engineConnection?.isReady()) { if (kclManager.engineCommandManager.engineConnection?.isReady()) {
// If the engine is ready, promptly execute the loaded code // If the engine is ready, promptly execute the loaded code
kclManager.executeCode(true) kclManager.executeCode(true, true)
} }
send({ type: 'Cancel' }) // in case the user hit 'Next' while still in sketch mode send({ type: 'Cancel' }) // in case the user hit 'Next' while still in sketch mode

View File

@ -57,7 +57,7 @@ function OnboardingWithNewFile() {
next={() => { next={() => {
// We do want to update both the state and editor here. // We do want to update both the state and editor here.
codeManager.updateCodeEditor(bracket) codeManager.updateCodeEditor(bracket)
kclManager.executeCode(true) kclManager.executeCode(true, true)
next() next()
}} }}
nextText="Overwrite code and continue" nextText="Overwrite code and continue"

View File

@ -14,7 +14,7 @@ export default function Sketching() {
codeManager.updateCodeEditor('') codeManager.updateCodeEditor('')
if (kclManager.engineCommandManager.engineConnection?.isReady()) { if (kclManager.engineCommandManager.engineConnection?.isReady()) {
// If the engine is ready, promptly execute the loaded code // If the engine is ready, promptly execute the loaded code
kclManager.executeCode(true) kclManager.executeCode(true, true)
} }
}, []) }, [])