Don't crash when trying to apply lastSelectionEvent selection that is out-of-range (#5644)

* Dumbest possible fix: don't let the `throw` propogate

* Add E2E test

* Fix lint
This commit is contained in:
Frank Noirot
2025-03-05 17:52:48 -05:00
committed by GitHub
parent bcac4d3798
commit e500fad0e1
2 changed files with 53 additions and 5 deletions

View File

@ -654,6 +654,50 @@ extrude001 = extrude(sketch001, length = 50)
await expect.poll(toolBarMode).toEqual('sketching') await expect.poll(toolBarMode).toEqual('sketching')
}) })
}) })
test(`Delete via feature tree then open code pane, never crash`, async ({
homePage,
toolbar,
editor,
context,
page,
scene,
cmdBar,
}) => {
await context.folderSetupFn(async (dir) => {
const bracketDir = path.join(dir, 'test-sample')
await fsp.mkdir(bracketDir, { recursive: true })
await fsp.writeFile(
path.join(bracketDir, 'main.kcl'),
`x = 5
plane001 = offsetPlane(XZ, offset = x)
plane002 = offsetPlane(XZ, offset = -2 * x)`
)
})
await homePage.openProject('test-sample')
await scene.waitForExecutionDone()
await expect(toolbar.startSketchBtn).toBeEnabled({ timeout: 20_000 })
const operationButton = await toolbar.getFeatureTreeOperation(
'Offset Plane',
1
)
await test.step('Delete offset plane via feature tree selection', async () => {
await expect(operationButton.last()).toBeVisible({ timeout: 10_000 })
await editor.closePane()
await operationButton.first().click({ button: 'left' })
await page.keyboard.press('Delete')
await scene.settled(cmdBar)
})
await test.step(`Open the code pane, don't crash`, async () => {
await editor.openPane()
await expect(page.getByText('unexpected error')).not.toBeVisible()
await editor.expectEditor.toContain(`x = 5`)
await editor.expectEditor.toContain(`plane001`)
await editor.expectEditor.not.toContain(`plane002`)
})
})
}) })
async function clickExportButton(page: Page) { async function clickExportButton(page: Page) {

View File

@ -96,11 +96,15 @@ export const KclEditorPane = () => {
return return
} }
try {
editorManager.editorView.dispatch({ editorManager.editorView.dispatch({
selection: lastSelectionEvent.codeMirrorSelection, selection: lastSelectionEvent.codeMirrorSelection,
annotations: [modelingMachineEvent, Transaction.addToHistory.of(false)], annotations: [modelingMachineEvent, Transaction.addToHistory.of(false)],
scrollIntoView: lastSelectionEvent.scrollIntoView, scrollIntoView: lastSelectionEvent.scrollIntoView,
}) })
} catch (e) {
console.error('Error setting selection', e)
}
}, [editorIsMounted, lastSelectionEvent]) }, [editorIsMounted, lastSelectionEvent])
const textWrapping = context.textEditor.textWrapping const textWrapping = context.textEditor.textWrapping