Skip to content

fix: prevent event propagation on paste and mouse down in rich text e… - #394

Merged
saa938 merged 1 commit into
AP-Students:mainfrom
Famousmaster206:text-bugs-on-website
Sep 3, 2026
Merged

fix: prevent event propagation on paste and mouse down in rich text e…#394
saa938 merged 1 commit into
AP-Students:mainfrom
Famousmaster206:text-bugs-on-website

Conversation

@Famousmaster206

Copy link
Copy Markdown
Contributor

Description

Fixes two text-editing bugs reported in #387:
Resolves #387

  1. Practice Questions paste duplication — pasting into the question rich-text editor (and the image caption editor) duplicated the pasted content, sometimes rendering it outside the intended editor box. Root cause: the custom onPaste handlers called event.preventDefault() but not event.stopPropagation(), so the native paste event still bubbled up to Editor.js's own delegated paste listener on its holder element. That listener only treats <input>/<textarea> as "native" and skips them — it doesn't recognize plain contentEditable divs — so it went ahead and inserted the same clipboard content a second time into whatever block/caret Editor.js considered "current," which could differ from the nested editor's own location.

  2. Caption hyperlink popover closing immediately — clicking the link button in the caption toolbar closed the popover before the URL field could be focused. Root cause: the toolbar button had no onMouseDown guard, so the mousedown itself blurred the contentEditable caption field before the button's onClick (which opens the popover) ran. The editor's handleBlur then closed the just-opened popover on its next animation frame.

Related: RichTextEditor.tsx for the Practice Questions body/options and CaptionRichTextEditor.tsx for image captions.

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

A summary of the change, anything else that will help review this PR

How Has This Been Tested? How can the reviewer test it?

Verified via code inspection/tracing of the event flow and confirmed tsc --noEmit shows no new type errors introduced by the changes.

To test manually:

Bug 1

  1. Open the article/question creator and add a Practice Question.
  2. Copy some plain text and some formatted (rich) text from another source.
  3. Paste each into the question text, an answer option, and the explanation field.
  4. Confirm the content appears exactly once, entirely inside the field pasted into, with no duplicate content elsewhere on the page.
  5. Repeat the paste a few times in the same field to confirm no cumulative duplication.
  6. Save and reload the article; confirm the saved question matches what was shown in the editor, and that pre-existing questions with pasted content still render correctly.

Bug 2

  1. Open an image caption in the article editor and select some caption text.
  2. Click the hyperlink button in the formatting toolbar.
  3. Confirm the URL popover stays open and the URL input is focused.
  4. Paste or type a URL into the field and click Apply — confirm the link is applied and the popover closes.
  5. Reopen the popover and click Cancel, and separately click outside the popover — confirm both dismiss it correctly.
  6. Save the article and confirm the hyperlink is still correctly attached to the caption text after reload.

Checklist

  • I have performed a self-review of my own code

@saa938
saa938 merged commit adc920b into AP-Students:main Sep 3, 2026
1 check passed
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.

Misc. Text Bugs on the website

2 participants