Skip to content

fix: prevent duplicate character when typing on selected blocks (Fixes #3012) - #3016

Open
waterWang wants to merge 1 commit into
codex-team:nextfrom
waterWang:fix/selection-typed-character-duplicated
Open

fix: prevent duplicate character when typing on selected blocks (Fixes #3012)#3016
waterWang wants to merge 1 commit into
codex-team:nextfrom
waterWang:fix/selection-typed-character-duplicated

Conversation

@waterWang

Copy link
Copy Markdown

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 clearSelection method in blockSelection.ts removes the selected blocks, inserts a default block, and programmatically inserts the typed character via Caret.insertContentAtCaretPosition after 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 the clearSelection method when a printable key is typed while blocks are selected, preventing the browser from also inserting the character. The editor's manual insertion via Caret.insertContentAtCaretPosition is the only insertion that occurs.

Technical details

  • File: src/components/modules/blockSelection.ts
  • The affected code path is in the clearSelection method, specifically when anyBlockSelected && isKeyboard && isPrintableKey && !SelectionUtils.isSelectionExists is true.
  • The preventDefault() call is added right at the start of this block, before the block removal and character insertion logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typed character is duplicated when replacing a selection (single block or cross-block)

1 participant