Skip to content
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
679669a
adding spell checker as an enabled mode
satti-hari-krishna-reddy Jun 16, 2024
896a77e
specifying path to spell checker
satti-hari-krishna-reddy Jun 16, 2024
a6958e2
included spell checker as a new mode
satti-hari-krishna-reddy Jun 16, 2024
12eb793
adding spell check as a link in the nav bar
satti-hari-krishna-reddy Jun 16, 2024
0138309
empty initial spell check component
satti-hari-krishna-reddy Jun 17, 2024
03ee1b5
fixing import for spell check component
satti-hari-krishna-reddy Jun 17, 2024
530cd5b
initial code for spell checker interface
satti-hari-krishna-reddy Jun 17, 2024
46ca008
fix issues with text rendering
satti-hari-krishna-reddy Jun 21, 2024
b35ca82
fixng styling
satti-hari-krishna-reddy Jun 21, 2024
45855bb
fixing issue with state updates with renderHighlightText
satti-hari-krishna-reddy Jun 22, 2024
f91abdd
adding handleSubmit function
satti-hari-krishna-reddy Jun 22, 2024
7c21473
refactoring SpellCheck component
satti-hari-krishna-reddy Jun 22, 2024
61fb332
removing unnecessary script
satti-hari-krishna-reddy Jun 22, 2024
554f455
trying to fix eslint issues
satti-hari-krishna-reddy Jun 28, 2024
30a2847
fixed lint errors
satti-hari-krishna-reddy Jun 28, 2024
1dae8d2
fixed a failing test case
satti-hari-krishna-reddy Jun 28, 2024
52d2efe
Merge branch 'apertium:master' into gsoc-speller-checker
satti-hari-krishna-reddy Jun 28, 2024
23b4597
fixing the text not showing up from local storage
satti-hari-krishna-reddy Jun 28, 2024
5587092
fixing prettier error and improving applySuggestion function
satti-hari-krishna-reddy Jun 28, 2024
bd0e486
saving and restoring caret position
satti-hari-krishna-reddy Jun 29, 2024
5940fae
getting available voikko modes
satti-hari-krishna-reddy Jul 26, 2024
67971dc
making sure to strip way any html tags
satti-hari-krishna-reddy Jul 26, 2024
ad0fdb1
renaming the apy endpoint for spell checking
satti-hari-krishna-reddy Jul 28, 2024
bf50986
test(SpellChecker): add initial unit test cases
satti-hari-krishna-reddy Jul 28, 2024
33877f0
reverting to spellers
satti-hari-krishna-reddy Jul 29, 2024
5269f1f
fix small circle issue when no suggestions are returned
satti-hari-krishna-reddy Aug 1, 2024
34a4554
Added logic for instant spell check triggered after a delay of 3 seco…
satti-hari-krishna-reddy Aug 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added logic for instant spell check triggered after a delay of 3 seco…
…nds from the last keystroke.
  • Loading branch information
satti-hari-krishna-reddy committed Aug 4, 2024
commit 34a4554bb557bd293665c809534753c9eecb97cc
25 changes: 25 additions & 0 deletions src/components/spellchecker/SpellChecker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const Spellers: Readonly<Record<string, string>> = (window as any).SPELLERS;

const langUrlParam = 'lang';
const textUrlParam = 'q';

const isKeyUpEvent = (event: React.SyntheticEvent): event is React.KeyboardEvent => event.type === 'keyup';

const SpellCheckForm = ({
setLoading,
setError,
Expand All @@ -45,6 +48,10 @@ const SpellCheckForm = ({
const initialRender = React.useRef<boolean>(true);
const spellcheckRef = React.useRef<HTMLDivElement | null>(null);
const spellcheckResult = React.useRef<CancelTokenSource | null>(null);
const spellCheckTimer = React.useRef<number | null>(null);

const instantSpellCheck = true;
const instantSpellCheckDelay = 3000;

const [lang, setLang] = useLocalStorage('spellerLang', Object.keys(Spellers)[0], {
overrideValue: toAlpha3Code(getUrlParam(history.location.search, langUrlParam)),
Expand Down Expand Up @@ -101,6 +108,23 @@ const SpellCheckForm = ({
})();
};

const handleInstantSpellCheck = (
event: React.KeyboardEvent<HTMLDivElement> | React.ClipboardEvent<HTMLDivElement>,
) => {
if (isKeyUpEvent(event) && (event.code === 'Space' || event.code === 'Enter')) {
return;
}

if (spellCheckTimer.current && instantSpellCheck) {
clearTimeout(spellCheckTimer.current);
}
spellCheckTimer.current = window.setTimeout(() => {
if (spellCheckTimer) {
handleSubmit();
}
}, instantSpellCheckDelay);
};

const handleWordClick = React.useCallback((word: string, event: MouseEvent | TouchEvent) => {
setSelectedWord(word);
const rect = (event.currentTarget as Element).getBoundingClientRect();
Expand Down Expand Up @@ -265,6 +289,7 @@ const SpellCheckForm = ({
handleSubmit();
}
}}
onKeyUp={handleInstantSpellCheck}
ref={spellcheckRef}
role="textbox"
tabIndex={0}
Expand Down