From 3872b72672ee4269ba75431cd4bb32227ff330b2 Mon Sep 17 00:00:00 2001 From: adueck Date: Mon, 22 Apr 2024 10:57:18 +0400 Subject: [PATCH] word selection shortcut now works with Pashto number keys --- website/src/App.tsx | 31 ++++++++++++++++++------------- website/src/lib/misc-helpers.ts | 10 ++++++++++ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/website/src/App.tsx b/website/src/App.tsx index 933af8d..1ce472d 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -73,6 +73,7 @@ import PhraseBuilder from "./screens/PhraseBuilder"; import { searchAllInflections } from "./lib/search-all-inflections"; import { addToWordlist } from "./lib/wordlist-database"; import ScriptToPhonetics from "./screens/ScriptToPhonetics"; +import { pNums, convertNumShortcutToNum } from "./lib/misc-helpers"; const newWordsPeriod: "week" | "month" = "week"; @@ -242,20 +243,24 @@ class App extends Component { }); } // shortcuts to isolote word in search results - Mousetrap.bind(["1", "2", "3", "4", "5", "6", "7", "8", "9"], (e) => { - e.preventDefault(); - if (e.repeat) { - return; + Mousetrap.bind( + ["1", "2", "3", "4", "5", "6", "7", "8", "9", ...pNums], + (e) => { + e.preventDefault(); + if (e.repeat) { + return; + } + if (this.props.location.pathname !== "/search") { + return; + } + const toIsolate = + this.state.results[convertNumShortcutToNum(e.key) - 1]; + if (!toIsolate) { + return; + } + this.handleIsolateEntry(toIsolate.ts); } - if (this.props.location.pathname !== "/search") { - return; - } - const toIsolate = this.state.results[Number(e.key) - 1]; - if (!toIsolate) { - return; - } - this.handleIsolateEntry(toIsolate.ts); - }); + ); Mousetrap.bind( ["ctrl+down", "ctrl+up", "command+down", "command+up"], (e) => { diff --git a/website/src/lib/misc-helpers.ts b/website/src/lib/misc-helpers.ts index 8370f7a..e02be6a 100644 --- a/website/src/lib/misc-helpers.ts +++ b/website/src/lib/misc-helpers.ts @@ -1,5 +1,15 @@ import * as AT from "../types/account-types"; +export const pNums: string[] = ["۱", "۲", "۳", "۴", "۵", "۶", "۷", "۷", "۹"]; + +export function convertNumShortcutToNum(k: string): number { + const pInd = pNums.findIndex((x) => k === x); + if (pInd > -1) { + return pInd + 1; + } + return Number(k); +} + export function objIsEqual(obj1: any, obj2: any): boolean { if (!obj1 || !obj2) return false; return JSON.stringify(obj1) === JSON.stringify(obj2);