-
Notifications
You must be signed in to change notification settings - Fork 5
feat: keyboard support for input area #41
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
960d0a0
c536e06
9ec8cb9
4f269ee
ec5359c
28450a2
5aa9b38
2d8e66c
d3c5a09
5410d74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| import { render, screen } from "@testing-library/preact"; | ||
| import "@testing-library/jest-dom"; | ||
| import { html } from "htm/preact"; | ||
| import { ContentBmwEncoding } from "./ContentBmwEncoding"; | ||
| import { ContentBmwEncoding, } from "./ContentBmwEncoding"; | ||
|
||
| import { initAdaptivePaletteGlobals } from "./GlobalData"; | ||
|
|
||
| test("The BMW Encoding content area is rendered correctly", async (): Promise<void> => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ import { html } from "htm/preact"; | |
| import { BlissSymbol } from "./BlissSymbol"; | ||
| import { changeEncodingContents } from "./GlobalData"; | ||
| import { ContentBmwEncodingType, EncodingType } from "./index.d"; | ||
| import { generateGridStyle } from "./GlobalUtils"; | ||
| import { generateGridStyle, clamp } from "./GlobalUtils"; | ||
| import "./ContentBmwEncoding.scss"; | ||
|
|
||
| export const INPUT_AREA_ID = "bmw-encoding-area"; // better way? | ||
|
|
@@ -66,6 +66,36 @@ function generateMarkupArray (payloadArray: Array<EncodingType>, caretPos: numbe | |
| }); | ||
| } | ||
|
|
||
| export function moveCursor (positionChange = 1) { | ||
|
||
| positionChange = Math.round(positionChange); | ||
|
||
|
|
||
| // Note: the new caretPosition can equal -1 indicating that the caret is before the | ||
| // first symbol in the `payloads` array. But, it cannot be less than -1. | ||
| const newPosition = clamp(changeEncodingContents.value.caretPosition + positionChange, -1, changeEncodingContents.value.payloads.length - 1); | ||
| changeEncodingContents.value = { | ||
| payloads: changeEncodingContents.value.payloads, | ||
| caretPosition: newPosition | ||
| }; | ||
| }; | ||
|
|
||
| export function incrementCursor () { | ||
| moveCursor(1); | ||
| } | ||
|
|
||
| export function decrementCursor () { | ||
| moveCursor(-1); | ||
| } | ||
|
|
||
| function handleKeyDown(event: KeyboardEvent) { | ||
| if (event.key === "ArrowLeft" || event.key === "ArrowDown") { | ||
| decrementCursor(); | ||
| } | ||
|
|
||
| if (event.key === "ArrowRight" || event.key === "ArrowUp") { | ||
| incrementCursor(); | ||
| } | ||
| } | ||
|
|
||
| export function ContentBmwEncoding (props: ContentBmwEncodingProps): VNode { | ||
| const { id, options } = props; | ||
| const { columnStart, columnSpan, rowStart, rowSpan } = options; | ||
|
|
@@ -76,7 +106,15 @@ export function ContentBmwEncoding (props: ContentBmwEncodingProps): VNode { | |
| ); | ||
|
|
||
| return html` | ||
| <div id="${id}" class="bmwEncodingArea" role="textbox" aria-label="Input Area" aria-readonly="true" style="${gridStyles}"> | ||
| <div | ||
| id="${id}" | ||
| class="bmwEncodingArea" | ||
| role="textbox" | ||
| aria-label="Input Area" | ||
| aria-readonly="true" | ||
| style="${gridStyles}" | ||
| tabindex="0" | ||
| onKeyDown=${handleKeyDown}> | ||
| ${contentsMarkupArray} | ||
| </div> | ||
| `; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,9 +102,26 @@ function insertWordAtCaret (wordToAdd: SymbolEncodingType, symbolSet: SymbolEnco | |
| return newSymbolSet; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the inputted value constrained to the `min` and `max` values. | ||
| * The returned value will: | ||
| * - `min` if `value` was less than `min` | ||
| * - `max` if the `value` was greater than `max` | ||
| * - `value` if it fell within the `min` `max` range. | ||
| * | ||
| * @param {number} value - The value to evaluate | ||
| * @param {number} min - The minimum value to be returned | ||
| * @param {number} max - The maximum value to be returned | ||
| * @returns {number} - The constrained value | ||
| */ | ||
| function clamp (value: number, min: number, max: number) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a note -- no change necessary. I thought that a |
||
| return Math.min(Math.max(value, min), max); | ||
| } | ||
|
|
||
| export { | ||
| generateGridStyle, | ||
| speak, | ||
| loadPaletteFromJsonFile, | ||
| insertWordAtCaret | ||
| insertWordAtCaret, | ||
| clamp | ||
| }; | ||
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.
Update the README to indicate the RAG support is optional. Can you also document the npm install commands for enabling or skipping this functionality.
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.
@cindyli I added some information in the README. Please let me know if it makes sense or if you'd like further changes.
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.
The update on README looks good to me. Thanks, @jobara.