clean up
This commit is contained in:
@ -329,7 +329,7 @@ export const FileMachineProvider = ({
|
||||
onSubmit: async (data) => {
|
||||
if (data.method === 'overwrite') {
|
||||
codeManager.updateCodeStateEditor(data.code)
|
||||
await kclManager.executeCode({ zoomToFit: true })
|
||||
await kclManager.executeCode(true)
|
||||
await codeManager.writeToFile()
|
||||
} else if (data.method === 'newFile' && isDesktop()) {
|
||||
send({
|
||||
|
@ -22,6 +22,7 @@ import usePlatform from 'hooks/usePlatform'
|
||||
import { FileEntry } from 'lib/project'
|
||||
import { useFileSystemWatcher } from 'hooks/useFileSystemWatcher'
|
||||
import { reportRejection } from 'lib/trap'
|
||||
import { normalizeLineEndings } from 'lib/codeEditor'
|
||||
|
||||
function getIndentationCSS(level: number) {
|
||||
return `calc(1rem * ${level + 1})`
|
||||
@ -189,25 +190,23 @@ const FileTreeItem = ({
|
||||
// Because subtrees only render when they are opened, that means this
|
||||
// only listens when they open. Because this acts like a useEffect, when
|
||||
// the ReactNodes are destroyed, so is this listener :)
|
||||
/** Disabling this in favor of faster file writes until we fix file writing **/
|
||||
/* useFileSystemWatcher(
|
||||
* async (eventType, path) => {
|
||||
* // Prevents a cyclic read / write causing editor problems such as
|
||||
* // misplaced cursor positions.
|
||||
* if (codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher) {
|
||||
* codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher = false
|
||||
* return
|
||||
* }
|
||||
|
||||
* if (isCurrentFile && eventType === 'change') {
|
||||
* let code = await window.electron.readFile(path, { encoding: 'utf-8' })
|
||||
* code = normalizeLineEndings(code)
|
||||
* codeManager.updateCodeStateEditor(code)
|
||||
* }
|
||||
* fileSend({ type: 'Refresh' })
|
||||
* },
|
||||
* [fileOrDir.path]
|
||||
* ) */
|
||||
useFileSystemWatcher(
|
||||
async (eventType, path) => {
|
||||
// Prevents a cyclic read / write causing editor problems such as
|
||||
// misplaced cursor positions.
|
||||
if (codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher) {
|
||||
codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher = false
|
||||
return
|
||||
}
|
||||
if (isCurrentFile && eventType === 'change') {
|
||||
let code = await window.electron.readFile(path, { encoding: 'utf-8' })
|
||||
code = normalizeLineEndings(code)
|
||||
codeManager.updateCodeStateEditor(code)
|
||||
}
|
||||
fileSend({ type: 'Refresh' })
|
||||
},
|
||||
[fileOrDir.path]
|
||||
)
|
||||
|
||||
const showNewTreeEntry =
|
||||
newTreeEntry !== undefined &&
|
||||
@ -263,7 +262,7 @@ const FileTreeItem = ({
|
||||
await codeManager.writeToFile()
|
||||
|
||||
// Prevent seeing the model built one piece at a time when changing files
|
||||
await kclManager.executeCode({ zoomToFit: true })
|
||||
await kclManager.executeCode(true)
|
||||
} else {
|
||||
// Let the lsp servers know we closed a file.
|
||||
onFileClose(currentFile?.path || null, project?.path || null)
|
||||
|
@ -124,7 +124,7 @@ const ProjectsContextWeb = ({ children }: { children: React.ReactNode }) => {
|
||||
clearImportSearchParams()
|
||||
codeManager.updateCodeStateEditor(input.code || '')
|
||||
await codeManager.writeToFile()
|
||||
await kclManager.executeCode({ zoomToFit: true })
|
||||
await kclManager.executeCode(true)
|
||||
|
||||
return {
|
||||
message: 'File overwritten successfully',
|
||||
|
@ -187,7 +187,7 @@ export const SettingsAuthProviderBase = ({
|
||||
) {
|
||||
// Unit changes requires a re-exec of code
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
kclManager.executeCode({ zoomToFit: true })
|
||||
kclManager.executeCode(true)
|
||||
} else {
|
||||
// For any future logging we'd like to do
|
||||
// console.log(
|
||||
|
@ -60,7 +60,7 @@ export const Stream = () => {
|
||||
*/
|
||||
function executeCodeAndPlayStream() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
kclManager.executeCode({ zoomToFit: true }).then(async () => {
|
||||
kclManager.executeCode(true).then(async () => {
|
||||
await videoRef.current?.play().catch((e) => {
|
||||
console.warn('Video playing was prevented', e, videoRef.current)
|
||||
})
|
||||
|
@ -457,7 +457,7 @@ export class KclManager {
|
||||
this._cancelTokens.set(key, true)
|
||||
})
|
||||
}
|
||||
async executeCode(opts?: { zoomToFit?: true }): Promise<void> {
|
||||
async executeCode(zoomToFit?: boolean): Promise<void> {
|
||||
const ast = await this.safeParse(codeManager.code)
|
||||
|
||||
if (!ast) {
|
||||
@ -465,10 +465,10 @@ export class KclManager {
|
||||
return
|
||||
}
|
||||
|
||||
// zoomToFit = this.tryToZoomToFitOnCodeUpdate(ast, opts?.zoomToFit)
|
||||
zoomToFit = this.tryToZoomToFitOnCodeUpdate(ast, zoomToFit)
|
||||
|
||||
this.ast = { ...ast }
|
||||
return this.executeAst(opts)
|
||||
return this.executeAst({ zoomToFit })
|
||||
}
|
||||
/**
|
||||
* This will override the zoom to fit to zoom into the model if the previous AST was empty.
|
||||
|
@ -157,7 +157,7 @@ export default class CodeManager {
|
||||
toast.error('Error saving file, please check file permissions')
|
||||
reject(err)
|
||||
})
|
||||
}, 10)
|
||||
}, 1000)
|
||||
})
|
||||
} else {
|
||||
safeLSSetItem(PERSIST_CODE_KEY, this.code)
|
||||
|
@ -50,7 +50,7 @@ process.chdir(DIR_KCL_SAMPLES)
|
||||
|
||||
beforeAll(async () => {
|
||||
await initPromise
|
||||
}, 5_000)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
try {
|
||||
@ -78,6 +78,6 @@ describe('Test KCL Samples from public Github repository', () => {
|
||||
},
|
||||
files.length * 1000
|
||||
)
|
||||
}, 3_0000)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -368,14 +368,12 @@ export type ModelingMachineEvent =
|
||||
tool: SketchTool
|
||||
}
|
||||
}
|
||||
// | { type: 'Finish rectangle' | 'Finish center rectangle' | 'Finish circle three point' | 'Finish circle' }
|
||||
| { type: 'Finish rectangle' }
|
||||
| { type: 'Finish center rectangle' }
|
||||
| { type: 'Finish circle' }
|
||||
| { type: 'Finish circle three point' }
|
||||
| { type: 'Artifact graph populated' }
|
||||
| { type: 'Artifact graph emptied' }
|
||||
// | { type: 'xstate.done.actor.actor-circle-three-point' }
|
||||
|
||||
export type MoveDesc = { line: number; snippet: string }
|
||||
|
||||
|
@ -94,7 +94,7 @@ function OnboardingWarningWeb(props: OnboardingResetWarningProps) {
|
||||
codeManager.updateCodeStateEditor(bracket)
|
||||
await codeManager.writeToFile()
|
||||
|
||||
await kclManager.executeCode({ zoomToFit: true })
|
||||
await kclManager.executeCode(true)
|
||||
props.setShouldShowWarning(false)
|
||||
}
|
||||
return () => {
|
||||
|
@ -8,7 +8,7 @@ export default function Sketching() {
|
||||
async function clearEditor() {
|
||||
// We do want to update both the state and editor here.
|
||||
codeManager.updateCodeStateEditor('')
|
||||
await kclManager.executeCode({ zoomToFit: true })
|
||||
await kclManager.executeCode(true)
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
|
@ -103,7 +103,7 @@ export function useDemoCode() {
|
||||
setTimeout(
|
||||
toSync(async () => {
|
||||
codeManager.updateCodeStateEditor(bracket)
|
||||
await kclManager.executeCode({ zoomToFit: true })
|
||||
await kclManager.executeCode(true)
|
||||
await codeManager.writeToFile()
|
||||
}, reportRejection)
|
||||
)
|
||||
|
Reference in New Issue
Block a user