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:
@ -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) {
|
||||||
|
@ -96,11 +96,15 @@ export const KclEditorPane = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
editorManager.editorView.dispatch({
|
try {
|
||||||
selection: lastSelectionEvent.codeMirrorSelection,
|
editorManager.editorView.dispatch({
|
||||||
annotations: [modelingMachineEvent, Transaction.addToHistory.of(false)],
|
selection: lastSelectionEvent.codeMirrorSelection,
|
||||||
scrollIntoView: lastSelectionEvent.scrollIntoView,
|
annotations: [modelingMachineEvent, Transaction.addToHistory.of(false)],
|
||||||
})
|
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
|
||||||
|
Reference in New Issue
Block a user