Skip to content
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

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open

Added Shortcuts to Analog #1236

wants to merge 53 commits into from

Conversation

julianchen215
Copy link

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

AmolK987 and others added 30 commits February 10, 2023 16:56
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.
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.
Can now bring up appropriate icon for input keyboard shortcut.

Also, completed set of common components.
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.
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
@AmolK987 AmolK987 linked an issue Mar 21, 2023 that may be closed by this pull request
Added shortcut parameters to Digital navbar.
Added shortcuts to the analog popup that reflects what was added.
Copy link
Member

@LeonMontealegre LeonMontealegre left a 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
Copy link
Member

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";
Copy link
Member

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){
Copy link
Member

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]){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add space between ) and {

Copy link
Contributor

@TGCrystal TGCrystal left a 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

  1. Open itemnav
  2. Press s
  3. right click
  4. Click Segment Display
  5. 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:

  1. Open itemnav
  2. Press s
  3. 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.

src/site/shared/containers/ItemNav/index.tsx Outdated Show resolved Hide resolved
julianchen215 and others added 20 commits March 24, 2023 16:34
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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ItemNav Keyboard Shortcuts
4 participants