Allow deletion of only item in AST (#6335)
* Update test to check for deletion of only operation * Allow updateEditorWithAstAndWriteToFile to clear AST * Update src/lang/codeManager.ts Co-authored-by: Jonathan Tran <jonnytran@gmail.com> * Weave `isDeleting` through to `deleteSelectionPromise` * fmt --------- Co-authored-by: Jonathan Tran <jonnytran@gmail.com> Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
This commit is contained in:
@ -165,13 +165,16 @@ export default class CodeManager {
|
||||
}
|
||||
}
|
||||
|
||||
async updateEditorWithAstAndWriteToFile(ast: Program) {
|
||||
async updateEditorWithAstAndWriteToFile(
|
||||
ast: Program,
|
||||
options?: Partial<{ isDeleting: boolean }>
|
||||
) {
|
||||
// We clear the AST when it cannot be parsed. If we are trying to write an
|
||||
// empty AST, it's probably because of an earlier error. That's a bad state
|
||||
// to be in, and it's not going to be pretty, but at the least, let's not
|
||||
// permanently delete the user's code. If you want to clear the scene, call
|
||||
// updateCodeStateEditor directly.
|
||||
if (ast.body.length === 0) return
|
||||
// permanently delete the user's code accidentally.
|
||||
// if you want to clear the scene, pass in the `isDeleting` option.
|
||||
if (ast.body.length === 0 && !options?.isDeleting) return
|
||||
const newCode = recast(ast)
|
||||
if (err(newCode)) return
|
||||
// Test to see if we can parse the recast code, and never update the editor with bad code.
|
||||
|
Reference in New Issue
Block a user