Skip to content

Commit

Permalink
#1934 – added charge tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitvex committed Dec 23, 2022
1 parent 9fc6b18 commit 2372fe6
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ export function handleHotkeyOverAtom(hoveredItemId, newAction, render, editor) {
}
if (newAction.tool === 'eraser') {
handleEraserTool(hoveredItemId, newAction, render, editor)
return
}
if (newAction.tool === 'select') {
handleSelectionTool(hoveredItemId, newAction, render, editor)
return
}
if (newAction.tool === 'charge') {
handleChargeTool(hoveredItemId, newAction, render, editor)
}
}

Expand Down Expand Up @@ -48,6 +53,21 @@ function handleEraserTool(hoveredItemId, _, render, editor) {

function handleSelectionTool(hoveredItemId, _, __, editor) {
editor.selection({
atoms: hoveredItemId
atoms: [hoveredItemId]
})
}

function handleChargeTool(hoveredItemId, newAction, render, editor) {
const existingAtom = render.ctab.atoms.get(hoveredItemId)?.a
if (existingAtom) {
const updatedAtom = fromAtomsAttrs(
render.ctab,
hoveredItemId,
{
charge: existingAtom.charge + newAction.opts.charge
},
null
)
editor.update(updatedAtom)
}
}

0 comments on commit 2372fe6

Please sign in to comment.