Skip to content

Commit

Permalink
add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ssg committed Jan 14, 2025
1 parent b3f5668 commit f11b945
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/view/com/composer/select-language/SuggestedLanguage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ export function SuggestedLanguage({text}: {text: string}) {
useEffect(() => {
let textTrimmed = text.trim()

// remove the last word before guessing to prevent a half-written word
// Remove the last word before guessing to prevent a half-written word
// from botching the confidence of language detection.
// There are two gotchas with this approach:
// First, it might increase the practical minimum length for the language
// detection because removing the last word would eat away from the
// 40 character min limit. I think it's worth it though.
// Second, this will also discard the last word that has been typed fully
// which might affect the outcome. One might consider detecting punctuation
// at the end of the last word to include it in the language detection,
// but it's quite hard to do that for all languages correctly.
const lastSpace = textTrimmed.lastIndexOf(' ')
if (lastSpace > 0) {
textTrimmed = textTrimmed.slice(0, lastSpace)
Expand Down

0 comments on commit f11b945

Please sign in to comment.