#4852 Delete line segments in sketch mode using keyboard (#6407)

* wip hack to delete line segments

* unrelated: clean up console

* better check if current selection is segment before deletion

* lint
This commit is contained in:
Andrew Varga
2025-04-28 16:27:11 +02:00
committed by GitHub
parent efba773635
commit a58a3361b6
2 changed files with 20 additions and 3 deletions

View File

@ -1967,8 +1967,27 @@ export const ModelingMachineProvider = ({
// `navigator.platform` is deprecated, but the alternative `navigator.userAgentData.platform` is not reliable
const deleteKeys =
platform() === 'macos' ? ['backspace', 'delete', 'del'] : ['delete', 'del']
useHotkeys(deleteKeys, () => {
modelingSend({ type: 'Delete selection' })
// When the current selection is a segment, delete that directly ('Delete selection' doesn't support it)
const segmentNodePaths = Object.keys(modelingState.context.segmentOverlays)
const selections =
modelingState.context.selectionRanges.graphSelections.filter((sel) =>
segmentNodePaths.includes(JSON.stringify(sel.codeRef.pathToNode))
)
selections.forEach((selection) => {
modelingSend({
type: 'Delete segment',
data: selection.codeRef.pathToNode,
})
})
if (
modelingState.context.selectionRanges.graphSelections.length >
selections.length
) {
// Not all selection were segments -> keep the default delete behavior
modelingSend({ type: 'Delete selection' })
}
})
// Allow ctrl+alt+c to center to selection