From 5e1b67bcbccc3394f8f2ebd67cc190dfe4e90f0d Mon Sep 17 00:00:00 2001 From: wisherhxl Date: Thu, 26 May 2022 08:47:55 +0800 Subject: [PATCH] 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. --- CONTRIBUTORS | 1 + ts/editor/rich-text-input/RichTextInput.svelte | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c54faccb2..0eafd0e5e 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -100,6 +100,7 @@ Bruce Harris Patric Cunha Brayan Oliveira Luka Warren +wisherhxl ******************** diff --git a/ts/editor/rich-text-input/RichTextInput.svelte b/ts/editor/rich-text-input/RichTextInput.svelte index 2eabbd29a..7409c3319 100644 --- a/ts/editor/rich-text-input/RichTextInput.svelte +++ b/ts/editor/rich-text-input/RichTextInput.svelte @@ -72,6 +72,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html async function moveCaretToEnd(): Promise { 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); }