-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete key binding #46
Comments
Hi, I did some workaround to try having a ( componentDidMount() {
document.addEventListener('keydown', this.handleKeyDown);
}
componentWillUnmount() {
document.removeEventListener('keydown', this.handleKeyDown);
}
handleKeyDown = (event: KeyboardEvent) => {
if (event.ctrlKey && event.key === 'x') {
this.removeSelectedObject();
}
};
removeSelectedObject = () => {
const { selectedNodes } = this.state;
if (selectedNodes.length === 0) {return;}
const objectId = selectedNodes[0]; // Assuming only one object is selected
const sharedModel = this.props.cpModel.jcadModel?.sharedModel;
if (!sharedModel) {
return;
}
const dependants = sharedModel.getDependants(objectId);
let body: React.JSX.Element;
if (dependants.length) {
body = (
<div>
{'Removing this object will also result in removing:'}
<ul>
{dependants.map(dependant => (
<li key={dependant}>{dependant}</li>
))}
</ul>
</div>
);
} else {
body = <div>Are you sure?</div>;
}
showDialog({
title: `Removing ${objectId}`,
body,
buttons: [Dialog.okButton(), Dialog.cancelButton()]
}).then(({ button: { accept } }) => {
if (accept) {
const toRemove = dependants.concat([objectId]);
sharedModel.removeObjects(toRemove);
}
});
this.props.cpModel.jcadModel?.syncSelected({});
}; And it works, I just copied the body of |
you might want to take a look at this PR geojupyter/jupytergis#58. jupytergis and jupytercad share a lot of codebase |
Thanks, this helps a lot. |
* #46 Define function to `handleRemoveObject` * #46 Bring `handleRemoveObject` in commands * `Ctrl` + `X` keybinding to remove object * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add handling if no object is selected * `[Delete]` Keybinding & Enable it on ObjectTree too * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Add a
Delete
key binding for removing shapesThe text was updated successfully, but these errors were encountered: