Skip to content

Commit

Permalink
Add keyboard shortcuts (#7)
Browse files Browse the repository at this point in the history
This adds Ctrl + F (focus on search bar) and Shift + + (add new node) keyboard shortcuts.
  • Loading branch information
TranquilMarmot committed Aug 3, 2020
1 parent 947714a commit b872a29
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Yarn Loom is a Visual Studio Code extension for editing [yarn files](https://yar
- [Quick tag search](#quick-tag-search)
- [Switching between the graph editor and a text editor](#switching-between-the-graph-editor-and-a-text-editor)
- [Theme support](#theme-support)
- [Keyboard Shortcuts](#keyboard-shortcuts)
- [Special Thanks](#special-thanks)

## Installing
Expand Down Expand Up @@ -171,6 +172,13 @@ If there is a theme where something doesn't look right or is unreadable, please
<img src="./images/theme-change.gif" alt="Demo of switching themes in Visual Studio Code" />
</details>

## Keyboard Shortcuts

| Shortcut | Description |
| ------------------------------- | ------------------- |
| <kbd>Ctrl</kbd> + <kbd>F</kbd> | Focus on search bar |
| <kbd>Shift</kbd> + <kbd>+</kbd> | Add new node |

## Special Thanks

The syntax highlighting portion of this extension was copied over from the [Yarn VSCode Extension](https://github.com/YarnSpinnerTool/VSCodeExtension) and all credit for it goes to [@desplesda](https://github.com/desplesda).
Expand Down
13 changes: 13 additions & 0 deletions loom-editor/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions loom-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"d3": "^5.16.0",
"loom-common": "file:../loom-common/out",
"react-d3-graph": "^2.5.0",
"react-hotkeys-hook": "^2.2.2",
"react-scripts": "3.4.1",
"typesafe-actions": "^5.1.0"
},
Expand Down
19 changes: 13 additions & 6 deletions loom-editor/src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
/** @jsx jsx */
import { jsx, css } from "@emotion/core";
import { FunctionComponent } from "react";
import { useHotkeys } from "react-hotkeys-hook";

import "./App.css";
import NodeGraph from "./NodeGraph";
import NodeSearch from "./NodeSearch";
import { createNewNode } from "loom-common/EditorActions";

const appStyle = css`
width: 100%;
height: 100%;
`;

const App: FunctionComponent = () => (
<div css={appStyle}>
<NodeSearch />
<NodeGraph />
</div>
);
const App: FunctionComponent = () => {
// shift and plus key add a new node (note that = is used since shift modifies it to be plus)
useHotkeys("shift+=", () => window.vsCodeApi.postMessage(createNewNode()));

return (
<div css={appStyle}>
<NodeSearch />
<NodeGraph />
</div>
);
};

export default App;
4 changes: 4 additions & 0 deletions loom-editor/src/components/NodeSearch/SearchBox.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @jsx jsx */
import { jsx, css } from "@emotion/core";
import { FunctionComponent, useRef } from "react";
import { useHotkeys } from "react-hotkeys-hook";

import { ReactComponent as CaseSensitiveIcon } from "../../icons/case-sensitive.svg";
import { ReactComponent as RegExIcon } from "../../icons/regex.svg";
Expand Down Expand Up @@ -106,6 +107,9 @@ const SearchBox: FunctionComponent = () => {
// used to focus back on the input when clicking buttons in this box
const inputRef = useRef<HTMLInputElement>(null);

// ctrl+f focuses on the input box
useHotkeys("ctrl+f", () => inputRef.current?.focus());

if (!state) {
return null;
}
Expand Down
8 changes: 8 additions & 0 deletions loom-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Yarn Loom is a Visual Studio Code extension for editing [yarn files](https://yar
- [Quick tag search](#quick-tag-search)
- [Switching between the graph editor and a text editor](#switching-between-the-graph-editor-and-a-text-editor)
- [Theme support](#theme-support)
- [Keyboard Shortcuts](#keyboard-shortcuts)
- [Special Thanks](#special-thanks)

## Usage
Expand Down Expand Up @@ -162,6 +163,13 @@ If there is a theme where something doesn't look right or is unreadable, please
<img src="https://github.com/TranquilMarmot/YarnLoom/raw/main/images/theme-change.gif" alt="Demo of switching themes in Visual Studio Code" />
</details>

## Keyboard Shortcuts

| Shortcut | Description |
| ------------------------------- | ------------------- |
| <kbd>Ctrl</kbd> + <kbd>F</kbd> | Focus on search bar |
| <kbd>Shift</kbd> + <kbd>+</kbd> | Add new node |

## Special Thanks

The syntax highlighting portion of this extension was copied over from the [Yarn VSCode Extension](https://github.com/YarnSpinnerTool/VSCodeExtension) and all credit for it goes to [@desplesda](https://github.com/desplesda).
Expand Down

0 comments on commit b872a29

Please sign in to comment.