Skip to content

Commit 29179c2

Browse files
author
Chengxi
committed
fix: Resolve issue with double-pinyin input not working on certain Linux applications
1 parent b670a30 commit 29179c2

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

background/controller.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,19 +302,38 @@ export class InputController extends EventEmitter {
302302
preeditEmpty: boolean;
303303
setComposition(param: chrome.input.ime.CompositionParameters): Promise<void> {
304304
return new Promise((res, rej) => {
305+
// Check if param and param.text are valid
306+
if (!param || (typeof param.text !== 'string')) {
307+
rej(new Error('Invalid param or param.text is not a string'));
308+
return;
309+
}
310+
// Replace all spaces in param.text with underscore
311+
// Using spaces may cause problems with Chinese character input within some Linux applications (such as QQ).
312+
param.text = param.text.replace(/\s+/g, '_');
305313
if (param.text.length == 0 && this.preeditEmpty) {
306-
// If preedit is already empty, and new preedit is also empty, then do not call
314+
// If preedit is already empty, and new preedit is also empty, then do not call
307315
// setComposition. This will mostly happen in ASCII mode (e.g. input method is
308316
// switched off by pressing Shift). If we still call setComposition in this case,
309317
// Chrome omnibar autofill text will disappear, resulting in bad user experience
310318
res(null);
311319
} else {
312320
this.preeditEmpty = param.text.length == 0;
313-
chrome.input.ime.setComposition(param, (ok) => ok ? res(null) : rej());
321+
try {
322+
chrome.input.ime.setComposition(param, (ok) => {
323+
if (chrome.runtime.lastError) {
324+
rej(new Error(chrome.runtime.lastError.message));
325+
} else {
326+
ok ? res(null) : rej();
327+
}
328+
});
329+
} catch (err) {
330+
rej(err);
331+
}
314332
}
315-
})
333+
});
316334
}
317335

336+
318337
sendCandidatesToInputView(candidates: Array<{ candidate: string, ix: number }>) {
319338
this.emit("candidatesBack", candidates);
320339
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fyde-rhythm",
33
"displayName": "FydeRhythm",
4-
"version": "2.0.11",
4+
"version": "2.0.12",
55
"description": "The FydeRhythm input method",
66
"author": "fydeos",
77
"packageManager": "[email protected]",

0 commit comments

Comments
 (0)