Feature: Disable all automatic zoom_to_fit
workflows. Do not take control of users camera. (#6076)
chore: removing all force zoom_to_fit workflows in the system except on initial stream load sending it
This commit is contained in:
@ -428,7 +428,7 @@ export const FileMachineProvider = ({
|
|||||||
onSubmit: async (data) => {
|
onSubmit: async (data) => {
|
||||||
if (data.method === 'overwrite') {
|
if (data.method === 'overwrite') {
|
||||||
codeManager.updateCodeStateEditor(data.code)
|
codeManager.updateCodeStateEditor(data.code)
|
||||||
await kclManager.executeCode(true)
|
await kclManager.executeCode()
|
||||||
await codeManager.writeToFile()
|
await codeManager.writeToFile()
|
||||||
} else if (data.method === 'newFile' && isDesktop()) {
|
} else if (data.method === 'newFile' && isDesktop()) {
|
||||||
send({
|
send({
|
||||||
|
@ -273,7 +273,7 @@ const FileTreeItem = ({
|
|||||||
await codeManager.writeToFile()
|
await codeManager.writeToFile()
|
||||||
|
|
||||||
// Prevent seeing the model built one piece at a time when changing files
|
// Prevent seeing the model built one piece at a time when changing files
|
||||||
await kclManager.executeCode(true)
|
await kclManager.executeCode()
|
||||||
} 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)
|
||||||
|
@ -132,7 +132,7 @@ const ProjectsContextWeb = ({ children }: { children: React.ReactNode }) => {
|
|||||||
if (err(codeToWrite)) return Promise.reject(codeToWrite)
|
if (err(codeToWrite)) return Promise.reject(codeToWrite)
|
||||||
codeManager.updateCodeStateEditor(codeToWrite)
|
codeManager.updateCodeStateEditor(codeToWrite)
|
||||||
await codeManager.writeToFile()
|
await codeManager.writeToFile()
|
||||||
await kclManager.executeCode(true)
|
await kclManager.executeCode()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
message: 'File overwritten successfully',
|
message: 'File overwritten successfully',
|
||||||
|
@ -25,6 +25,7 @@ import {
|
|||||||
} from '@src/lib/singletons'
|
} from '@src/lib/singletons'
|
||||||
import { err, reportRejection } from '@src/lib/trap'
|
import { err, reportRejection } from '@src/lib/trap'
|
||||||
import type { IndexLoaderData } from '@src/lib/types'
|
import type { IndexLoaderData } from '@src/lib/types'
|
||||||
|
import { uuidv4 } from '@src/lib/utils'
|
||||||
import { useSettings } from '@src/machines/appMachine'
|
import { useSettings } from '@src/machines/appMachine'
|
||||||
import { useCommandBarState } from '@src/machines/commandBarMachine'
|
import { useCommandBarState } from '@src/machines/commandBarMachine'
|
||||||
|
|
||||||
@ -67,11 +68,23 @@ export const Stream = () => {
|
|||||||
*/
|
*/
|
||||||
function executeCodeAndPlayStream() {
|
function executeCodeAndPlayStream() {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
kclManager.executeCode(true).then(async () => {
|
kclManager.executeCode().then(async () => {
|
||||||
await videoRef.current?.play().catch((e) => {
|
await videoRef.current?.play().catch((e) => {
|
||||||
console.warn('Video playing was prevented', e, videoRef.current)
|
console.warn('Video playing was prevented', e, videoRef.current)
|
||||||
})
|
})
|
||||||
setStreamState(StreamState.Playing)
|
setStreamState(StreamState.Playing)
|
||||||
|
|
||||||
|
// Only call zoom_to_fit once when the stream starts to center the scene.
|
||||||
|
await 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
|
||||||
|
animated: false, // don't animate the zoom for now
|
||||||
|
},
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,12 +57,7 @@ import { deferExecution, isOverlap, uuidv4 } from '@src/lib/utils'
|
|||||||
|
|
||||||
interface ExecuteArgs {
|
interface ExecuteArgs {
|
||||||
ast?: Node<Program>
|
ast?: Node<Program>
|
||||||
zoomToFit?: boolean
|
|
||||||
executionId?: number
|
executionId?: number
|
||||||
zoomOnRangeAndType?: {
|
|
||||||
range: SourceRange
|
|
||||||
type: string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class KclManager {
|
export class KclManager {
|
||||||
@ -435,27 +430,6 @@ export class KclManager {
|
|||||||
if (!isInterrupted) {
|
if (!isInterrupted) {
|
||||||
this.addDiagnostics(await lintAst({ ast: ast }))
|
this.addDiagnostics(await lintAst({ ast: ast }))
|
||||||
await setSelectionFilterToDefault(this.engineCommandManager)
|
await setSelectionFilterToDefault(this.engineCommandManager)
|
||||||
|
|
||||||
if (args.zoomToFit) {
|
|
||||||
let zoomObjectId: string | undefined = ''
|
|
||||||
if (args.zoomOnRangeAndType) {
|
|
||||||
zoomObjectId = this.mapRangeToObjectId(
|
|
||||||
args.zoomOnRangeAndType.range,
|
|
||||||
args.zoomOnRangeAndType.type
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.engineCommandManager.sendSceneCommand({
|
|
||||||
type: 'modeling_cmd_req',
|
|
||||||
cmd_id: uuidv4(),
|
|
||||||
cmd: {
|
|
||||||
type: 'zoom_to_fit',
|
|
||||||
object_ids: zoomObjectId ? [zoomObjectId] : [], // leave empty to zoom to all objects
|
|
||||||
padding: 0.1, // padding around the objects
|
|
||||||
animated: false, // don't animate the zoom for now
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isExecuting = false
|
this.isExecuting = false
|
||||||
@ -560,7 +534,7 @@ export class KclManager {
|
|||||||
this._cancelTokens.set(key, true)
|
this._cancelTokens.set(key, true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
async executeCode(zoomToFit?: boolean): Promise<void> {
|
async executeCode(): Promise<void> {
|
||||||
const ast = await this.safeParse(codeManager.code)
|
const ast = await this.safeParse(codeManager.code)
|
||||||
|
|
||||||
if (!ast) {
|
if (!ast) {
|
||||||
@ -570,36 +544,10 @@ export class KclManager {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
zoomToFit = this.tryToZoomToFitOnCodeUpdate(ast, zoomToFit)
|
|
||||||
|
|
||||||
this.ast = { ...ast }
|
this.ast = { ...ast }
|
||||||
return this.executeAst({ zoomToFit })
|
return this.executeAst()
|
||||||
}
|
|
||||||
/**
|
|
||||||
* This will override the zoom to fit to zoom into the model if the previous AST was empty.
|
|
||||||
* Workflows this improves,
|
|
||||||
* When someone comments the entire file then uncomments the entire file it zooms to the model
|
|
||||||
* When someone CTRL+A and deletes the code then adds the code back it zooms to the model
|
|
||||||
* When someone CTRL+A and copies new code into the editor it zooms to the model
|
|
||||||
*/
|
|
||||||
tryToZoomToFitOnCodeUpdate(
|
|
||||||
ast: Node<Program>,
|
|
||||||
zoomToFit: boolean | undefined
|
|
||||||
) {
|
|
||||||
const isAstEmpty = this._isAstEmpty(this._ast)
|
|
||||||
const isRequestedAstEmpty = this._isAstEmpty(ast)
|
|
||||||
|
|
||||||
// If the AST went from empty to not empty or
|
|
||||||
// If the user has all of the content selected and they copy new code in
|
|
||||||
if (
|
|
||||||
(isAstEmpty && !isRequestedAstEmpty) ||
|
|
||||||
editorManager.isAllTextSelected
|
|
||||||
) {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return zoomToFit
|
|
||||||
}
|
|
||||||
async format() {
|
async format() {
|
||||||
const originalCode = codeManager.code
|
const originalCode = codeManager.code
|
||||||
const ast = await this.safeParse(originalCode)
|
const ast = await this.safeParse(originalCode)
|
||||||
@ -633,11 +581,6 @@ export class KclManager {
|
|||||||
execute: boolean,
|
execute: boolean,
|
||||||
optionalParams?: {
|
optionalParams?: {
|
||||||
focusPath?: Array<PathToNode>
|
focusPath?: Array<PathToNode>
|
||||||
zoomToFit?: boolean
|
|
||||||
zoomOnRangeAndType?: {
|
|
||||||
range: SourceRange
|
|
||||||
type: string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
): Promise<{
|
): Promise<{
|
||||||
newAst: Node<Program>
|
newAst: Node<Program>
|
||||||
@ -687,8 +630,6 @@ export class KclManager {
|
|||||||
if (execute) {
|
if (execute) {
|
||||||
await this.executeAst({
|
await this.executeAst({
|
||||||
ast: astWithUpdatedSource,
|
ast: astWithUpdatedSource,
|
||||||
zoomToFit: optionalParams?.zoomToFit,
|
|
||||||
zoomOnRangeAndType: optionalParams?.zoomOnRangeAndType,
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// When we don't re-execute, we still want to update the program
|
// When we don't re-execute, we still want to update the program
|
||||||
|
@ -10,7 +10,7 @@ import type { Node } from '@rust/kcl-lib/bindings/Node'
|
|||||||
import type EditorManager from '@src/editor/manager'
|
import type EditorManager from '@src/editor/manager'
|
||||||
import type { KclManager } from '@src/lang/KclSingleton'
|
import type { KclManager } from '@src/lang/KclSingleton'
|
||||||
import type CodeManager from '@src/lang/codeManager'
|
import type CodeManager from '@src/lang/codeManager'
|
||||||
import type { PathToNode, Program, SourceRange } from '@src/lang/wasm'
|
import type { PathToNode, Program } from '@src/lang/wasm'
|
||||||
import type { ExecutionType } from '@src/lib/constants'
|
import type { ExecutionType } from '@src/lib/constants'
|
||||||
import {
|
import {
|
||||||
EXECUTION_TYPE_MOCK,
|
EXECUTION_TYPE_MOCK,
|
||||||
@ -52,11 +52,6 @@ export async function updateModelingState(
|
|||||||
},
|
},
|
||||||
options?: {
|
options?: {
|
||||||
focusPath?: Array<PathToNode>
|
focusPath?: Array<PathToNode>
|
||||||
zoomToFit?: boolean
|
|
||||||
zoomOnRangeAndType?: {
|
|
||||||
range: SourceRange
|
|
||||||
type: string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Step 1: Update AST without executing (prepare selections)
|
// Step 1: Update AST without executing (prepare selections)
|
||||||
@ -83,8 +78,6 @@ export async function updateModelingState(
|
|||||||
if (executionType === EXECUTION_TYPE_REAL) {
|
if (executionType === EXECUTION_TYPE_REAL) {
|
||||||
await dependencies.kclManager.executeAst({
|
await dependencies.kclManager.executeAst({
|
||||||
ast: updatedAst.newAst,
|
ast: updatedAst.newAst,
|
||||||
zoomToFit: options?.zoomToFit,
|
|
||||||
zoomOnRangeAndType: options?.zoomOnRangeAndType,
|
|
||||||
})
|
})
|
||||||
} else if (executionType === EXECUTION_TYPE_MOCK) {
|
} else if (executionType === EXECUTION_TYPE_MOCK) {
|
||||||
await dependencies.kclManager.executeAstMock(updatedAst.newAst)
|
await dependencies.kclManager.executeAstMock(updatedAst.newAst)
|
||||||
|
@ -1779,11 +1779,6 @@ export const modelingMachine = setup({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
focusPath: [pathToExtrudeArg],
|
focusPath: [pathToExtrudeArg],
|
||||||
zoomToFit: true,
|
|
||||||
zoomOnRangeAndType: {
|
|
||||||
range: selection.graphSelections[0]?.codeRef.range,
|
|
||||||
type: 'path',
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
@ -1860,11 +1855,6 @@ export const modelingMachine = setup({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
focusPath: [pathToRevolveArg],
|
focusPath: [pathToRevolveArg],
|
||||||
zoomToFit: true,
|
|
||||||
zoomOnRangeAndType: {
|
|
||||||
range: selection.graphSelections[0]?.codeRef.range,
|
|
||||||
type: 'path',
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
|
@ -245,7 +245,7 @@ export const settingsMachine = setup({
|
|||||||
|
|
||||||
if (shouldExecute) {
|
if (shouldExecute) {
|
||||||
// Unit changes requires a re-exec of code
|
// Unit changes requires a re-exec of code
|
||||||
kclManager.executeCode(true).catch(reportRejection)
|
kclManager.executeCode().catch(reportRejection)
|
||||||
} else {
|
} else {
|
||||||
// For any future logging we'd like to do
|
// For any future logging we'd like to do
|
||||||
// console.log(
|
// console.log(
|
||||||
|
@ -97,7 +97,7 @@ function OnboardingWarningWeb(props: OnboardingResetWarningProps) {
|
|||||||
codeManager.updateCodeStateEditor(bracket)
|
codeManager.updateCodeStateEditor(bracket)
|
||||||
await codeManager.writeToFile()
|
await codeManager.writeToFile()
|
||||||
|
|
||||||
await kclManager.executeCode(true)
|
await kclManager.executeCode()
|
||||||
props.setShouldShowWarning(false)
|
props.setShouldShowWarning(false)
|
||||||
}
|
}
|
||||||
return () => {
|
return () => {
|
||||||
|
@ -10,7 +10,7 @@ export default function Sketching() {
|
|||||||
async function clearEditor() {
|
async function clearEditor() {
|
||||||
// We do want to update both the state and editor here.
|
// We do want to update both the state and editor here.
|
||||||
codeManager.updateCodeStateEditor('')
|
codeManager.updateCodeStateEditor('')
|
||||||
await kclManager.executeCode(true)
|
await kclManager.executeCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
|
@ -53,7 +53,7 @@ export function useDemoCode() {
|
|||||||
setTimeout(
|
setTimeout(
|
||||||
toSync(async () => {
|
toSync(async () => {
|
||||||
codeManager.updateCodeStateEditor(bracket)
|
codeManager.updateCodeStateEditor(bracket)
|
||||||
await kclManager.executeCode(true)
|
await kclManager.executeCode()
|
||||||
await codeManager.writeToFile()
|
await codeManager.writeToFile()
|
||||||
}, reportRejection)
|
}, reportRejection)
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user