Fix ibus first keystroke goes two (#1886)

Calling `moveCaretToEnd()` when `richText` is empty will cause the first keystroke of
ibus-based input methods with candidates to goes double. For example, if you
type "a" it becomes "aa". This problem exists in many linux distributions.
When `richText` is empty, there is no need to place the caret, just return
as a workaround.
This commit is contained in:
wisherhxl 2022-05-26 08:47:55 +08:00 committed by GitHub
parent e50d40cedf
commit 5e1b67bcbc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -100,6 +100,7 @@ Bruce Harris <github.com/bruceharris>
Patric Cunha <patricc@agap2.pt>
Brayan Oliveira <github.com/BrayanDSO>
Luka Warren <github.com/lukawarren>
wisherhxl <wisherhxl@gmail.com>
********************

View file

@ -72,6 +72,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
async function moveCaretToEnd(): Promise<void> {
const richText = await richTextPromise;
if (richText.textContent?.length === 0) {
// Calling this method when richText is empty will cause the first keystroke of
// ibus-based input methods with candidates to go double. For example, if you
// type "a" it becomes "aa". This problem exists in many linux distributions.
// When richText is empty, there is no need to place the caret, just return.
return;
}
placeCaretAfterContent(richText);
}