You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/src/components/ContextMenu.tsx
+32-32Lines changed: 32 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,8 @@ function ContextMenu({
13
13
mouseXState,
14
14
mouseYState,
15
15
selectedItem,
16
+
menuTypeState,
17
+
selectedItemId,
16
18
targetColor,
17
19
PanRef
18
20
}){
@@ -31,9 +33,7 @@ function ContextMenu({
31
33
//@ts-ignore
32
34
constcontextParam=useSelector((store: RootState)=>store.contextSlice);// this is literally just passed in on everything else, i have no idea what it does, you can look it up, but other files are literally just taking it and passing it back in.
33
35
34
-
constMenuTypeRef=useRef('?');
35
-
36
-
letselectedItemId=useRef(-1);// dont trigger rerenders cause this shouldent change.
36
+
//let selectedItemId = useRef(-1); // dont trigger rerenders cause this shouldent change.
letthing=selectedItem;// look up th dom to see when we get to an element we like (if you right click on the span element you should still count as clicking the ReactTypeComponent element)
56
-
for(leti=0;i<5;i++){
57
-
// just things that we want to stop on...
58
-
if(!thing.id||!thing.id.match(/canv/)){
59
-
thing=thing.parentElement;
60
-
}else{
61
-
// once were all said and done...
62
-
if(thing.id.match(/^canv[0-9]/)){
63
-
MenuTypeRef.current='CanvasElement';
64
-
}else{
65
-
MenuTypeRef.current='?';// set this back to unknown if you click out.
66
-
}
53
+
// // set the focus on focus change
54
+
// useEffect(() => {
55
+
// let thing = selectedItem; // look up th dom to see when we get to an element we like (if you right click on the span element you should still count as clicking the ReactTypeComponent element)
56
+
// for (let i = 0; i < 5; i++) {
57
+
// // just things that we want to stop on...
58
+
// if (!thing.id || !thing.id.match(/canv/)) {
59
+
// thing = thing.parentElement;
60
+
// } else {
61
+
// // once were all said and done...
62
+
// if (thing.id.match(/^canv[0-9]/)) {
63
+
// MenuTypeRef.current = 'CanvasElement';
64
+
// } else {
65
+
// MenuTypeRef.current = '?'; // set this back to unknown if you click out.
66
+
// }
67
67
68
-
selectedItemId.current=Number(thing.id.split('canv')[1]);// this code tells us what hypothetical reaactType item we are selected, not just which DOM element.
69
-
break;
70
-
}
71
-
}
68
+
// selectedItemId.current = Number(thing.id.split('canv')[1]); // this code tells us what hypothetical reaactType item we are selected, not just which DOM element.
69
+
// break;
70
+
// }
71
+
// }
72
72
73
-
dispatch({
74
-
type: 'appState/changeFocus',
75
-
payload: {
76
-
componentId: appState.canvasFocus.componentId,
77
-
childId: selectedItemId.current
78
-
}
79
-
});
80
-
},[selectedItem]);// re trigger if the position of the context menu changes.
73
+
// dispatch({
74
+
// type: 'appState/changeFocus',
75
+
// payload: {
76
+
// componentId: appState.canvasFocus.componentId,
77
+
//childId: selectedItemId.current // no more current
78
+
// }
79
+
// });
80
+
// }, [selectedItem]); // re trigger if the position of the context menu changes.
81
81
82
82
// remove the keystroke listener on unmount.
83
83
useEffect(
@@ -99,7 +99,7 @@ function ContextMenu({
99
99
100
100
letcorrectChild=searchChildren(
101
101
appState.components[0].children,
102
-
selectedItemId.current
102
+
selectedItemId
103
103
);// helper function below
104
104
105
105
letfullAttributes=correctChild[stateTarget];
@@ -138,7 +138,7 @@ function ContextMenu({
138
138
139
139
letcorrectChild=searchChildren(
140
140
appState.components[0].children,// this is simply searching for the correct actual component from the dom elemnt ref
e.preventDefault();// grab that event trigger, or maybe this writes to something, idk
103
+
console.log(e.target);
100
104
if(
101
105
ContextMenuRef.current!=null&&
102
106
ContextMenuRef.current.contains(e.target)
103
107
){
108
+
e.preventDefault();// grab that event trigger, or maybe this writes to something, idk
104
109
return;// if it is not nul and we are clicking in it.
105
110
}
106
-
setContextMenuSelectedElement(e.target);// get it set it
107
111
108
-
setMouseXState(MouseXRef.current);
109
-
setMouseYState(MouseYRef.current);// now trigger a re-render
110
-
setContextMenuOpen(true);
112
+
// set the focus on focus change
113
+
letwillGrabDefault=true;
114
+
letthing=e.target;// look up th dom to see when we get to an element we like (if you right click on the span element you should still count as clicking the ReactTypeComponent element)
115
+
for(leti=0;i<5;i++){
116
+
// just things that we want to stop on...
117
+
if(!thing.id||!thing.id.match(/canv/)){
118
+
thing=thing.parentElement;
119
+
}else{
120
+
// once were all said and done...
121
+
if(thing.id.match(/^canv[0-9]/)){
122
+
setMenuTypeState('CanvasElement');
123
+
}else{
124
+
willGrabDefault=false;
125
+
setMenuTypeState('?');// set this back to unknown if you click out.
126
+
}
127
+
128
+
setSelectedItemIdState(Number(thing.id.split('canv')[1]));// this code tells us what hypothetical reaactType item we are selected, not just which DOM element.
129
+
break;
130
+
}
131
+
}
132
+
if(willGrabDefault){
133
+
e.preventDefault();// gdouble
134
+
dispatch({
135
+
type: 'appState/changeFocus',
136
+
payload: {
137
+
componentId: appState.canvasFocus.componentId,
138
+
childId: selectedItemIdState
139
+
}
140
+
});
141
+
142
+
setContextMenuSelectedElement(e.target);// get it set it
143
+
144
+
setMouseXState(MouseXRef.current);
145
+
setMouseYState(MouseYRef.current);// now trigger a re-render
146
+
setContextMenuOpen(true);
147
+
}
111
148
});
112
149
onmousemove=function(e){
113
150
MouseXRef.current=e.clientX;// this is a use ref, not use state, so we dont trigger a re-render.
0 commit comments