Skip to content

Commit

Permalink
transliteration minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
prtkjakhar committed Feb 1, 2024
1 parent 109f1ee commit 44b2fd8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
7 changes: 5 additions & 2 deletions apps/amakrushi/src/components/HomePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const HomePage: NextPage = () => {
transliterationConfig.serviceId ||
'ai4bharat/indicxlit--cpu-fsv2',
isSentence: false,
numSuggestions: 5,
numSuggestions: 3,
},
},
],
Expand Down Expand Up @@ -289,7 +289,10 @@ const HomePage: NextPage = () => {

// Replace the selected word with the transliterated suggestion
if (selectedWord !== '') {
const newInputMsg = inputMsg.replace(selectedWord, e);
const newInputMsg = inputMsg.replace(
selectedWord,
cursorPosition === inputMsg.length ? e + ' ' : e
);

setSuggestions([]);
setSuggestionClicked(true);
Expand Down
2 changes: 1 addition & 1 deletion packages/chat-ui/dist/index.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions packages/chat-ui/es/components/Composer/ComposerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export var ComposerInput = function ComposerInput(_ref) {
},
serviceId: transliterationConfig.serviceId || 'ai4bharat/indicxlit--cpu-fsv2',
isSentence: false,
numSuggestions: 5
numSuggestions: 3
}
}],
inputData: {
Expand Down Expand Up @@ -170,14 +170,17 @@ export var ComposerInput = function ComposerInput(_ref) {
if (selectedWord) {
// Replace the selected word with the transliterated suggestion
//@ts-ignore
var newInputMsg = value.replace(selectedWord, e);
var newInputMsg = value.replace(selectedWord,
//@ts-ignore
cursorPosition === value.length ? e + ' ' : e);
setSuggestions([]);
setSuggestionClicked(true);
setActiveSuggestion(0);

// Save and restore the cursor position
var restoredCursorPosition =
//@ts-ignore
var restoredCursorPosition = cursorPosition - value.indexOf(selectedWord) + value.indexOf(e);
cursorPosition - value.indexOf(selectedWord) + value.indexOf(e);
//@ts-ignore
onChange(newInputMsg, e);
setCursorPosition(restoredCursorPosition);
Expand Down
9 changes: 6 additions & 3 deletions packages/chat-ui/lib/components/Composer/ComposerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ var ComposerInput = function ComposerInput(_ref) {
},
serviceId: transliterationConfig.serviceId || 'ai4bharat/indicxlit--cpu-fsv2',
isSentence: false,
numSuggestions: 5
numSuggestions: 3
}
}],
inputData: {
Expand Down Expand Up @@ -180,14 +180,17 @@ var ComposerInput = function ComposerInput(_ref) {
if (selectedWord) {
// Replace the selected word with the transliterated suggestion
//@ts-ignore
var newInputMsg = value.replace(selectedWord, e);
var newInputMsg = value.replace(selectedWord,
//@ts-ignore
cursorPosition === value.length ? e + ' ' : e);
setSuggestions([]);
setSuggestionClicked(true);
setActiveSuggestion(0);

// Save and restore the cursor position
var restoredCursorPosition =
//@ts-ignore
var restoredCursorPosition = cursorPosition - value.indexOf(selectedWord) + value.indexOf(e);
cursorPosition - value.indexOf(selectedWord) + value.indexOf(e);
//@ts-ignore
onChange(newInputMsg, e);
setCursorPosition(restoredCursorPosition);
Expand Down
13 changes: 9 additions & 4 deletions packages/chat-ui/src/components/Composer/ComposerInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const ComposerInput = ({
},
serviceId: transliterationConfig.serviceId || 'ai4bharat/indicxlit--cpu-fsv2',
isSentence: false,
numSuggestions: 5,
numSuggestions: 3,
},
},
],
Expand Down Expand Up @@ -178,16 +178,21 @@ export const ComposerInput = ({
if (selectedWord) {
// Replace the selected word with the transliterated suggestion
//@ts-ignore
const newInputMsg = value.replace(selectedWord, e);
const newInputMsg = value.replace(
selectedWord,
//@ts-ignore
cursorPosition === value.length ? e + ' ' : e,
);

setSuggestions([]);
setSuggestionClicked(true);
setActiveSuggestion(0);

// Save and restore the cursor position
const restoredCursorPosition =
//@ts-ignore
cursorPosition - value.indexOf(selectedWord) + value.indexOf(e);
//@ts-ignore
const restoredCursorPosition = cursorPosition - value.indexOf(selectedWord) + value.indexOf(e);
//@ts-ignore
onChange(newInputMsg, e);
setCursorPosition(restoredCursorPosition);
//@ts-ignore
Expand Down

0 comments on commit 44b2fd8

Please sign in to comment.