@@ -34,6 +34,7 @@ interface IDrawArea {
3434 setIgnoreAreas : ( ignoreAreas : IgnoreArea [ ] ) => void ;
3535 selectedRectId : string | undefined ;
3636 setSelectedRectId : ( id : string ) => void ;
37+ deleteIgnoreArea ?: ( id :string ) => void ;
3738 onStageClick : ( event : Konva . KonvaEventObject < MouseEvent > ) => void ;
3839 stageOffsetState : [
3940 { x : number ; y : number } ,
@@ -64,6 +65,7 @@ export const DrawArea: FunctionComponent<IDrawArea> = ({
6465 setIgnoreAreas,
6566 selectedRectId,
6667 setSelectedRectId,
68+ deleteIgnoreArea,
6769 onStageClick,
6870 stageScaleState,
6971 stageOffsetState,
@@ -83,6 +85,27 @@ export const DrawArea: FunctionComponent<IDrawArea> = ({
8385 const [ isDrawMode , setIsDrawMode ] = drawModeState ;
8486 const [ isDrawing , setIsDrawing ] = React . useState ( isDrawMode ) ;
8587 const [ image , imageStatus ] = imageState ;
88+ const stageRef = React . useRef < Konva . Stage > ( null ) ;
89+
90+ React . useEffect ( ( ) => {
91+ if ( stageRef . current ) {
92+ const container = stageRef . current . container ( ) ;
93+ container . addEventListener ( 'keydown' , handleStageKeyDown ) ;
94+ }
95+ } , [ ] ) ;
96+
97+ const isModifierKeyPressed = ( e :any ) => {
98+ return e . altKey || e . ctrlKey || e . shiftKey ;
99+ } ;
100+
101+ const handleStageKeyDown = ( e :any ) => {
102+ if ( ! deleteIgnoreArea || isModifierKeyPressed ( e ) ) {
103+ return ;
104+ }
105+ if ( selectedRectId && ( e . key === 'Delete' || e . key === 'Backspace' ) ) {
106+ deleteIgnoreArea ( selectedRectId ) ;
107+ }
108+ } ;
86109
87110 const scrollContainerRef = React . useRef < HTMLDivElement > ( null ) ;
88111
@@ -91,6 +114,11 @@ export const DrawArea: FunctionComponent<IDrawArea> = ({
91114 } , [ stageScollPos ] ) ;
92115
93116 const handleContentMousedown = ( e : any ) => {
117+ if ( stageRef . current ) {
118+ const container = stageRef . current . container ( ) ;
119+ container . tabIndex = 1 ;
120+ container . focus ( ) ;
121+ }
94122 if ( ! isDrawMode ) return ;
95123
96124 const newArea : IgnoreArea = {
@@ -195,8 +223,10 @@ export const DrawArea: FunctionComponent<IDrawArea> = ({
195223 y : event . clientY - stageOffset . y ,
196224 } ) ;
197225 } }
226+ onKeyDown = { ( e ) => handleStageKeyDown ( e ) }
198227 >
199228 < Stage
229+ ref = { stageRef }
200230 width = { image && image . width }
201231 height = { image && image . height }
202232 onMouseDown = { onStageClick }
0 commit comments