Skip to content

Commit

Permalink
refactor: rename functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aradzie committed Apr 2, 2024
1 parent e7f65f7 commit 896edf7
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 24 deletions.
20 changes: 10 additions & 10 deletions packages/keybr-keyboard/lib/keyboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,26 @@ test("data", (t) => {
const kc0x00e1 = new KeyCombo(/* á */ 0x00e1, "KeyA", None, kc0x0301);

t.deepEqual(
[...keyboard.codePoints({ dead: true, shift: true, alt: true })],
[...keyboard.getCodePoints({ dead: true, shift: true, alt: true })],
[
/* A */ 0x0041, /* B */ 0x0042, /* a */ 0x0061, /* b */ 0x0062,
/* À */ 0x00c0, /* Á */ 0x00c1, /* à */ 0x00e0, /* á */ 0x00e1,
],
);
t.deepEqual(
[...keyboard.codePoints({ dead: false, shift: true, alt: true })],
[...keyboard.getCodePoints({ dead: false, shift: true, alt: true })],
[/* A */ 0x0041, /* B */ 0x0042, /* a */ 0x0061, /* b */ 0x0062],
);
t.deepEqual(
[...keyboard.codePoints({ dead: false, shift: true, alt: false })],
[...keyboard.getCodePoints({ dead: false, shift: true, alt: false })],
[/* A */ 0x0041, /* a */ 0x0061],
);
t.deepEqual(
[...keyboard.codePoints({ dead: false, shift: false, alt: true })],
[...keyboard.getCodePoints({ dead: false, shift: false, alt: true })],
[/* a */ 0x0061, /* b */ 0x0062],
);
t.deepEqual(
[...keyboard.codePoints({ dead: false, shift: false, alt: false })],
[...keyboard.getCodePoints({ dead: false, shift: false, alt: false })],
[/* a */ 0x0061],
);

Expand All @@ -82,9 +82,9 @@ test("data", (t) => {
t.is(shape1.finger, "indexRight");
t.is(shape1.hand, "right");
t.is(shape1.row, null);
t.deepEqual(keyboard.getShapesInZone("left"), [shape0]);
t.deepEqual(keyboard.getShapesInZone("right"), [shape1]);
t.deepEqual(keyboard.getShapesInZone("indexLeft"), [shape0]);
t.deepEqual(keyboard.getShapesInZone("indexRight"), [shape1]);
t.deepEqual(keyboard.getShapesInZone("home"), []);
t.deepEqual(keyboard.zones.get("left"), [shape0]);
t.deepEqual(keyboard.zones.get("right"), [shape1]);
t.deepEqual(keyboard.zones.get("indexLeft"), [shape0]);
t.deepEqual(keyboard.zones.get("indexRight"), [shape1]);
t.is(keyboard.zones.get("home"), undefined);
});
6 changes: 1 addition & 5 deletions packages/keybr-keyboard/lib/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ export class Keyboard {
return this.shapes.get(id) ?? null;
}

getShapesInZone(id: ZoneId): readonly KeyShape[] {
return this.zones.get(id) ?? [];
}

codePoints({
getCodePoints({
dead = true,
shift = true,
alt = true,
Expand Down
2 changes: 1 addition & 1 deletion packages/keybr-keyboard/lib/keycharacters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class KeyCharacters {
readonly d: CodePoint,
) {}

codePoint(modifier: KeyModifier): CodePoint {
getCodePoint(modifier: KeyModifier): CodePoint {
const { a, b, c, d } = this;
switch (modifier) {
case KeyModifier.None:
Expand Down
2 changes: 1 addition & 1 deletion packages/keybr-keyboard/lib/keyshape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class KeyShape {
this.row = selectZone(KeyShape.rowZones, this.zones);
}

isZone(id: ZoneId): boolean {
inZone(id: ZoneId): boolean {
return this.zones.includes(id);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/keybr-keyboard/lib/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ for (const layout of Layout.ALL) {
for (const geometry of layout.geometries) {
test(`load layout ${layout.id}/${geometry.id}`, (t) => {
const keyboard = loadKeyboard(layout, geometry);
const codePoints = keyboard.codePoints({
const codePoints = keyboard.getCodePoints({
dead: true,
shift: true,
alt: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/keybr-keyboard/lib/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function computeStats(
for (const { a: x, f } of ng1) {
const key = getShape(x);
if (key != null) {
if (key.isZone(zone)) {
if (key.inZone(zone)) {
a += f;
} else {
b += f;
Expand Down
2 changes: 1 addition & 1 deletion packages/keybr-lesson-loader/lib/LessonLoader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test.serial("load", async (t) => {
<KeyboardContext.Provider
value={
{
codePoints() {
getCodePoints() {
return codePointsFrom("abc");
},
} as Keyboard
Expand Down
2 changes: 1 addition & 1 deletion packages/keybr-lesson-loader/lib/LessonLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function useLoader(model: PhoneticModel): Lesson | null {
let didCancel = false;

const load = async (): Promise<void> => {
const codePoints = keyboard.codePoints();
const codePoints = keyboard.getCodePoints();
const newModel = PhoneticModel.restrict(model, codePoints);
const lessonType = settings.get(lessonProps.type);
const layout = settings.get(keyboardProps.layout);
Expand Down
2 changes: 1 addition & 1 deletion packages/keybr-textinput-events/lib/emulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function remap(
const characters = layout.getCharacters(code);
let codePoint = 0x0000;
if (characters != null) {
codePoint = characters.codePoint(KeyModifier.from({ shiftKey, altKey }));
codePoint = characters.getCodePoint(KeyModifier.from({ shiftKey, altKey }));
if (codePoint > 0x0000) {
key = String.fromCodePoint(codePoint);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/page-practice/lib/settings/KeyboardSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function PointersPreview(): ReactNode {
const [index, setIndex] = useState(0);
const suffix = useMemo(() => {
setIndex(0);
const codePoints = keyboard.codePoints();
const codePoints = keyboard.getCodePoints();
return getExampleText(keyboard.layout.language).filter((codePoint) =>
codePoints.has(codePoint),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/page-profile/lib/profile/ResultGrouper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function ResultGrouper({
case "letters":
return children(
newKeyStatsMap(
Letter.restrict(letters, keyboard.codePoints()),
Letter.restrict(letters, keyboard.getCodePoints()),
group,
),
);
Expand Down

0 comments on commit 896edf7

Please sign in to comment.