Skip to content

Commit

Permalink
fix: Resolve issue with double-pinyin input not working on certain Li…
Browse files Browse the repository at this point in the history
…nux applications
  • Loading branch information
Chengxi committed Jul 28, 2023
1 parent b670a30 commit 29179c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 22 additions & 3 deletions background/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,38 @@ export class InputController extends EventEmitter {
preeditEmpty: boolean;
setComposition(param: chrome.input.ime.CompositionParameters): Promise<void> {
return new Promise((res, rej) => {
// Check if param and param.text are valid
if (!param || (typeof param.text !== 'string')) {
rej(new Error('Invalid param or param.text is not a string'));
return;
}
// Replace all spaces in param.text with underscore
// Using spaces may cause problems with Chinese character input within some Linux applications (such as QQ).
param.text = param.text.replace(/\s+/g, '_');
if (param.text.length == 0 && this.preeditEmpty) {
// If preedit is already empty, and new preedit is also empty, then do not call
// If preedit is already empty, and new preedit is also empty, then do not call
// setComposition. This will mostly happen in ASCII mode (e.g. input method is
// switched off by pressing Shift). If we still call setComposition in this case,
// Chrome omnibar autofill text will disappear, resulting in bad user experience
res(null);
} else {
this.preeditEmpty = param.text.length == 0;
chrome.input.ime.setComposition(param, (ok) => ok ? res(null) : rej());
try {
chrome.input.ime.setComposition(param, (ok) => {
if (chrome.runtime.lastError) {
rej(new Error(chrome.runtime.lastError.message));
} else {
ok ? res(null) : rej();
}
});
} catch (err) {
rej(err);
}
}
})
});
}


sendCandidatesToInputView(candidates: Array<{ candidate: string, ix: number }>) {
this.emit("candidatesBack", candidates);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fyde-rhythm",
"displayName": "FydeRhythm",
"version": "2.0.11",
"version": "2.0.12",
"description": "The FydeRhythm input method",
"author": "fydeos",
"packageManager": "pnpm@8.3.1",
Expand Down

0 comments on commit 29179c2

Please sign in to comment.