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
Added Shortcuts to Analog #1236
base: master
Are you sure you want to change the base?
Conversation
Added series RC and RLC example circuits
- Added images files - Added example files
Handler for keyboard shortcut "v" to quickly create a new voltage source
An unfinished attempt at a keyboard shortcut for the resistor component.
…nCircuits into Updated_Analog1
Instead of using "Handlers" we will augment the current "ItemNav" and "AnalogItemNav" to support keyboard shortcuts
Added some explanatory comments for added code. Also, added placeholder functionality for any keyboard input
Changed keyboard popup redo to "ctrl + y" instead of "ctrl + shift + z". Also added a 2d array in the analogItemNav. Added a loop that will travers through the 2d array, looking if ev key matches any shorcut keys.
…nCircuits into Updated_Analog1
Can now bring up appropriate icon for input keyboard shortcut. Also, completed set of common components.
…nCircuits into Updated_Analog1
Detailed plan for future improvements to the analog OpenCircuits
Included detailed documentation on how a DC Analysis could be performed.
Detailed future functionality of uploading component files and being able to use that component in your circuit.
Added description of output report functionality
The keyboard shortcuts now work for spawning and placing one instance of a selected component.
Added a boolean called shortcut_flag that will remain true until escape is pressed. Still trying to figure out how to do this.
The keyboard shortcuts will support the placement of multiple placements of a component (on repeat clicks) until "Esc" is pressed.
…nCircuits into Updated_Analog1
Fixed small error in declaring shortcut_flag and added comment to the event of dropping a component for the unique case of using a shortcut.
When shortcut was added to analog, digital did not work. Fixed it.
Random commit to test/debug pulling from origin
…nCircuits into Updated_Analog1
Added shortcut parameters to Digital navbar.
Added shortcuts to the analog popup that reflects what was added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick review for now, will take a more thorough look later once you've fixed all of the linting errors (which you should please do)
getImgSrc: (c: Component) => string; | ||
onStart?: () => void; | ||
onFinish?: (cancelled: boolean) => void; | ||
onDelete?: (section: ItemNavSection, item: ItemNavItem) => boolean; | ||
additionalPreview?: (data: D, curItemID: string) => React.ReactNode; | ||
} | ||
export const ItemNav = <D,>({ info, config, additionalData, getImgSrc, onDelete, | ||
let shortcut_flag:boolean = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No no, gotta make a React state variable for this, look at useState
as it's used in the ItemNav already
Also please make sure to follow the style guidelines that the rest of OpenCircuits uses, i.e. camelCase naming
@@ -31,6 +31,7 @@ import {DragDropHandlers} from "shared/components/DragDroppable/DragDropHandlers | |||
import {Draggable} from "shared/components/DragDroppable/Draggable"; | |||
|
|||
import styles from "./index.scss"; | |||
import { boolean } from "yargs"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
// Loops through the shorcuts 2d array in AnalogItemNav to see if any shortcuts | ||
useDocEvent("keydown", (ev) => { | ||
// Loop through each of the input shortcuts | ||
for (var short of shortcuts){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never use var, use let
or const
, (const
here)
useDocEvent("keydown", (ev) => { | ||
// Loop through each of the input shortcuts | ||
for (var short of shortcuts){ | ||
if (ev.key === short[0]){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space between )
and {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionality wise, I think pressing the same shortcut for whatever item is currently selected (like if you press s
after you already did once to select Switch) then it should unselect it just like right clicking does.
Bugs wise, the only issues I found relate to dragging an item from the item nav while a shortcut is being used
- Open itemnav
- Press s
- right click
- Click Segment Display
- Click canvas to place Segment Display
It still tries to display a preview to place (it shouldn't), and it isn't finding an image to preview so it displays the alt placeholder text. Strangely enough, it does find a preview if you use Clock instead of Segment Display, although it still shouldn't have a preview.
A similar issue happens when:
- Open itemnav
- Press s
- Drag an Segment Display onto the itemnav
The preview is still there (and still fails to display).
Aside from that and the fixes proposed by the linter and Leon, this looks good! I do like this new functionality quite a bit, it feels much more ergonomic and useful than I expected.
Co-authored-by: Trevor Crystal <TGCrystal@users.noreply.github.com>
Implemented some of the requested changes.
Fixed a bug where the user stops using a shortcut, but code thinks shortcut was pressed for some element. Also includes debug prints
Trying to debug and attempt to fix the bug where the shortcut flag only works after the first initial placement.
Fixed all bugs with the shortcut feature after swapping to using state variables. This includes the bugs with getting stuck in the shortcut state even after exiting.
Fixed some of the lint errors and got rid of ocnsole log statements.
…nCircuits into Updated_Analog1
Now, users can exit the shortcut by pressing the same key again as well as pressing escape
Now, if a user opens the ItemNav with a shortcut active and selects the same component as the shortcut then the shortcut state is exited and the code will act like a normal ItemNav selection.
We have succesfully added keyboard shortcuts to the Analog version of OpenCircuits:
“V” for voltage source
“G” for ground
“R” for Resistor
“C” for capacitor
“L” for inductor
“I” for current source