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) => {
|
||||
if (data.method === 'overwrite') {
|
||||
codeManager.updateCodeStateEditor(data.code)
|
||||
await kclManager.executeCode(true)
|
||||
await kclManager.executeCode()
|
||||
await codeManager.writeToFile()
|
||||
} else if (data.method === 'newFile' && isDesktop()) {
|
||||
send({
|
||||
|
@ -273,7 +273,7 @@ const FileTreeItem = ({
|
||||
await codeManager.writeToFile()
|
||||
|
||||
// Prevent seeing the model built one piece at a time when changing files
|
||||
await kclManager.executeCode(true)
|
||||
await kclManager.executeCode()
|
||||
} else {
|
||||
// Let the lsp servers know we closed a file.
|
||||
onFileClose(currentFile?.path || null, project?.path || null)
|
||||
|
@ -132,7 +132,7 @@ const ProjectsContextWeb = ({ children }: { children: React.ReactNode }) => {
|
||||
if (err(codeToWrite)) return Promise.reject(codeToWrite)
|
||||
codeManager.updateCodeStateEditor(codeToWrite)
|
||||
await codeManager.writeToFile()
|
||||
await kclManager.executeCode(true)
|
||||
await kclManager.executeCode()
|
||||
|
||||
return {
|
||||
message: 'File overwritten successfully',
|
||||
|
@ -25,6 +25,7 @@ import {
|
||||
} from '@src/lib/singletons'
|
||||
import { err, reportRejection } from '@src/lib/trap'
|
||||
import type { IndexLoaderData } from '@src/lib/types'
|
||||
import { uuidv4 } from '@src/lib/utils'
|
||||
import { useSettings } from '@src/machines/appMachine'
|
||||
import { useCommandBarState } from '@src/machines/commandBarMachine'
|
||||
|
||||
@ -67,11 +68,23 @@ export const Stream = () => {
|
||||
*/
|
||||
function executeCodeAndPlayStream() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
kclManager.executeCode(true).then(async () => {
|
||||
kclManager.executeCode().then(async () => {
|
||||
await videoRef.current?.play().catch((e) => {
|
||||
console.warn('Video playing was prevented', e, videoRef.current)
|
||||
})
|
||||
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 {
|
||||
ast?: Node<Program>
|
||||
zoomToFit?: boolean
|
||||
executionId?: number
|
||||
zoomOnRangeAndType?: {
|
||||
range: SourceRange
|
||||
type: string
|
||||
}
|
||||
}
|
||||
|
||||
export class KclManager {
|
||||
@ -435,27 +430,6 @@ export class KclManager {
|
||||
if (!isInterrupted) {
|
||||
this.addDiagnostics(await lintAst({ ast: ast }))
|
||||
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
|
||||
@ -560,7 +534,7 @@ export class KclManager {
|
||||
this._cancelTokens.set(key, true)
|
||||
})
|
||||
}
|
||||
async executeCode(zoomToFit?: boolean): Promise<void> {
|
||||
async executeCode(): Promise<void> {
|
||||
const ast = await this.safeParse(codeManager.code)
|
||||
|
||||
if (!ast) {
|
||||
@ -570,36 +544,10 @@ export class KclManager {
|
||||
return
|
||||
}
|
||||
|
||||
zoomToFit = this.tryToZoomToFitOnCodeUpdate(ast, zoomToFit)
|
||||
|
||||
this.ast = { ...ast }
|
||||
return this.executeAst({ zoomToFit })
|
||||
}
|
||||
/**
|
||||
* 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 this.executeAst()
|
||||
}
|
||||
|
||||
return zoomToFit
|
||||
}
|
||||
async format() {
|
||||
const originalCode = codeManager.code
|
||||
const ast = await this.safeParse(originalCode)
|
||||
@ -633,11 +581,6 @@ export class KclManager {
|
||||
execute: boolean,
|
||||
optionalParams?: {
|
||||
focusPath?: Array<PathToNode>
|
||||
zoomToFit?: boolean
|
||||
zoomOnRangeAndType?: {
|
||||
range: SourceRange
|
||||
type: string
|
||||
}
|
||||
}
|
||||
): Promise<{
|
||||
newAst: Node<Program>
|
||||
@ -687,8 +630,6 @@ export class KclManager {
|
||||
if (execute) {
|
||||
await this.executeAst({
|
||||
ast: astWithUpdatedSource,
|
||||
zoomToFit: optionalParams?.zoomToFit,
|
||||
zoomOnRangeAndType: optionalParams?.zoomOnRangeAndType,
|
||||
})
|
||||
} else {
|
||||
// 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 { KclManager } from '@src/lang/KclSingleton'
|
||||
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 {
|
||||
EXECUTION_TYPE_MOCK,
|
||||
@ -52,11 +52,6 @@ export async function updateModelingState(
|
||||
},
|
||||
options?: {
|
||||
focusPath?: Array<PathToNode>
|
||||
zoomToFit?: boolean
|
||||
zoomOnRangeAndType?: {
|
||||
range: SourceRange
|
||||
type: string
|
||||
}
|
||||
}
|
||||
): Promise<void> {
|
||||
// Step 1: Update AST without executing (prepare selections)
|
||||
@ -83,8 +78,6 @@ export async function updateModelingState(
|
||||
if (executionType === EXECUTION_TYPE_REAL) {
|
||||
await dependencies.kclManager.executeAst({
|
||||
ast: updatedAst.newAst,
|
||||
zoomToFit: options?.zoomToFit,
|
||||
zoomOnRangeAndType: options?.zoomOnRangeAndType,
|
||||
})
|
||||
} else if (executionType === EXECUTION_TYPE_MOCK) {
|
||||
await dependencies.kclManager.executeAstMock(updatedAst.newAst)
|
||||
|
@ -1779,11 +1779,6 @@ export const modelingMachine = setup({
|
||||
},
|
||||
{
|
||||
focusPath: [pathToExtrudeArg],
|
||||
zoomToFit: true,
|
||||
zoomOnRangeAndType: {
|
||||
range: selection.graphSelections[0]?.codeRef.range,
|
||||
type: 'path',
|
||||
},
|
||||
}
|
||||
)
|
||||
}),
|
||||
@ -1860,11 +1855,6 @@ export const modelingMachine = setup({
|
||||
},
|
||||
{
|
||||
focusPath: [pathToRevolveArg],
|
||||
zoomToFit: true,
|
||||
zoomOnRangeAndType: {
|
||||
range: selection.graphSelections[0]?.codeRef.range,
|
||||
type: 'path',
|
||||
},
|
||||
}
|
||||
)
|
||||
}),
|
||||
|
@ -245,7 +245,7 @@ export const settingsMachine = setup({
|
||||
|
||||
if (shouldExecute) {
|
||||
// Unit changes requires a re-exec of code
|
||||
kclManager.executeCode(true).catch(reportRejection)
|
||||
kclManager.executeCode().catch(reportRejection)
|
||||
} else {
|
||||
// For any future logging we'd like to do
|
||||
// console.log(
|
||||
|
@ -97,7 +97,7 @@ function OnboardingWarningWeb(props: OnboardingResetWarningProps) {
|
||||
codeManager.updateCodeStateEditor(bracket)
|
||||
await codeManager.writeToFile()
|
||||
|
||||
await kclManager.executeCode(true)
|
||||
await kclManager.executeCode()
|
||||
props.setShouldShowWarning(false)
|
||||
}
|
||||
return () => {
|
||||
|
@ -10,7 +10,7 @@ export default function Sketching() {
|
||||
async function clearEditor() {
|
||||
// We do want to update both the state and editor here.
|
||||
codeManager.updateCodeStateEditor('')
|
||||
await kclManager.executeCode(true)
|
||||
await kclManager.executeCode()
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
|
@ -53,7 +53,7 @@ export function useDemoCode() {
|
||||
setTimeout(
|
||||
toSync(async () => {
|
||||
codeManager.updateCodeStateEditor(bracket)
|
||||
await kclManager.executeCode(true)
|
||||
await kclManager.executeCode()
|
||||
await codeManager.writeToFile()
|
||||
}, reportRejection)
|
||||
)
|
||||
|
Reference in New Issue
Block a user