fix: prevent duplicate character when typing on selected blocks (Fixes #3012) - #3016
Open
waterWang wants to merge 1 commit into
Open
fix: prevent duplicate character when typing on selected blocks (Fixes #3012)#3016waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
waterWang
requested review from
TatianaFomina,
gohabereg,
ilyamore88 and
neSpecc
as code owners
August 11, 2026 08:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #3012 — Typed character is duplicated when replacing a selection (single block or cross-block).
Root cause
When blocks are selected and a printable key is typed, the
clearSelectionmethod inblockSelection.tsremoves the selected blocks, inserts a default block, and programmatically inserts the typed character viaCaret.insertContentAtCaretPositionafter a 20ms delay. However, the keyboard event was NOT being prevented (preventDefault()was missing), so the browser's native keydown handler also inserted the character at the caret position, resulting in the character appearing twice.Fix
Added
event.preventDefault()in theclearSelectionmethod when a printable key is typed while blocks are selected, preventing the browser from also inserting the character. The editor's manual insertion viaCaret.insertContentAtCaretPositionis the only insertion that occurs.Technical details
src/components/modules/blockSelection.tsclearSelectionmethod, specifically whenanyBlockSelected && isKeyboard && isPrintableKey && !SelectionUtils.isSelectionExistsis true.preventDefault()call is added right at the start of this block, before the block removal and character insertion logic.