Skip to content

Conversation

@BryanValverdeU
Copy link
Contributor

@BryanValverdeU BryanValverdeU commented May 22, 2025

This PR ensures only one mousemove handler is attached when dragging selections and adds tests to verify this behavior.

  • Added a guard in SelectionPlugin to prevent multiple mousemove attachments
  • Updated tests to cover duplicate mouseDown calls and assert single attachment

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures only one mousemove handler is attached when dragging selections and adds tests to verify this behavior.

  • Added a guard in SelectionPlugin to prevent multiple mousemove attachments
  • Updated tests to cover duplicate mouseDown calls and assert single attachment

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/roosterjs-content-model-core/lib/corePlugin/selection/SelectionPlugin.ts Prevent duplicate mousemove event attachments by checking mouseDisposer
packages/roosterjs-content-model-core/test/corePlugin/selection/SelectionPluginTest.ts Add tests to simulate repeated mouseDown and assert only one attachment
Comments suppressed due to low confidence (4)

packages/roosterjs-content-model-core/lib/corePlugin/selection/SelectionPlugin.ts:222

  • [nitpick] For clarity and consistency with the test's mouseMoveDisposer, consider renaming mouseDisposer to mouseMoveDisposer.
if (!this.state.mouseDisposer) {

packages/roosterjs-content-model-core/test/corePlugin/selection/SelectionPluginTest.ts:898

  • Consider spying on editor.attachDomEvent here and asserting toHaveBeenCalledTimes(1) to explicitly verify that duplicate mouseDown events do not attach additional handlers.
expect(mouseDispatcher).toBeDefined();

packages/roosterjs-content-model-core/lib/corePlugin/selection/SelectionPlugin.ts:221

  • [nitpick] Add a brief comment above the guard to explain that this prevents multiple mousemove attachments when a second mouseDown occurs before mouseUp.
//

packages/roosterjs-content-model-core/lib/corePlugin/selection/SelectionPlugin.ts:230

  • This closing brace may prematurely end the onPluginEvent method. Verify that the if (!this.state.mouseDisposer) check and its corresponding logic remain inside the intended mouseDown handling block.
    }

@JiuqingSong JiuqingSong self-requested a review May 22, 2025 23:55
},
});
if (!this.state.mouseDisposer) {
this.state.mouseDisposer = editor.attachDomEvent({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about we just dispose the previous one and then attach a new one? I'm afraid if in a corner case this may cause the event can never be attached.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for me, changed in latest commit.

@BryanValverdeU BryanValverdeU enabled auto-merge (squash) May 23, 2025 15:01
@BryanValverdeU BryanValverdeU merged commit 617f46b into master May 23, 2025
7 checks passed
ianeli1 added a commit that referenced this pull request May 24, 2025
* Use FormatContainer to represent DIV with id (#3003)

* Fix #3005 (#3007)

* Fix a cache issue (#3006)

* Refactor getStyleMetadata to not rely on DomCreator and only use String handling (#3010)

* Refactor paste plugin to remove unused DOMCreator parameter and enhance style extraction logic

* fix test

* Change search string to lowercase

* Clean image edit when undo (#3015)

* undo image

* undo image

* undo image

* Add 'CustomCopyCut' experimental feature to fix some copy cut bugs (#3000)

* Add 'CustomCopyCut' experimental feature to enhance copy/cut behavior

* Implement pruneUnselectedModel utility for optimizing copy/paste behavior

* Try fix iuld

* Address comment and fix broken tests

* Revert unneeded change

* Refactor pruneUnselectedModel

---------

Co-authored-by: Jiuqing Song <jisong@microsoft.com>

* Demo site: Add preset content for undeleteable anchor (#3014)

Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>

* Revert "Refactor getStyleMetadata to not rely on DomCreator and only use Stri…" (#3020)

This reverts commit 5bbab35.

* Add API playground for createModelFromHTML (#3019)

* Add API playground for createModelFromHTML

* imporve

---------

Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>

* Do not copy div ID on Enter (#3011)

* wip

* insertCustom

* refactor

* formatKeys

* Add image hidden marker (#3021)

Instead of using a dataset to store the isEditing property, a hidden property is now used. To support this, get/set functions and the ImageMarkerFormat were introduced. The imageMarker property can now be accessed through the format property of the image.
This change eliminates the need to manually remove the dataset from the image element when extracting content from the DOM.

* Include ImageMetadata in FormatState (#3023)

* Support List Pasting from PowerPoint Desktop (#3012)

* Refactor paste parsers: add removeNegativeTextIndentParser and deprecatedBorderColorParser; update imports and constants for bullet list types

* Update packages/roosterjs-content-model-plugins/lib/paste/PowerPoint/processPastedContentFromPowerPoint.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor bullet list constants and improve format parser signatures

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Remove comments `<!--` and `-->` from styles and re apply fix for Word Desktop Pasting  (#3024)

* Update dependencies and enhance paste functionality by cleaning HTML comments in style tags

* Reapply "Refactor getStyleMetadata to not rely on DomCreator and only use Stri…" (#3020)

This reverts commit 32f47bf.

* Enhance cleanHtmlComments to handle both HTML comment formats in style tags

* Set original DOMPurify

* Update packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/getStyleMetadata.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Ensure headEndIndex is valid

* address comment

* Address comments

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Jiuqing Song <jisong@microsoft.com>

* insert link in the image (#3027)

When the image is selected, do not replace the image with the link, add the link to image segment.

* square (#3029)

Instead of using a square character, this change updates the square style to use the 'square' style.

* Normalize default format (#3028)

* Normalize default format

* improve

---------

Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>

* auto link (#3026)

* Add margin-inline-start to watermark styles for improved positioning (#3031)

* Allow queryContentModelBlocks to query blocks in entities (#3032)

* Allow queryContentModelBlocks to search children of entity

* Expect EditorContext instead

* Break out createEditorContextForEntity function into separate file and add tests

* Fix 353323: Keep indentation when start a list, and refactor (#3033)

* 353323

* fix build, add test

* improve

* Edit plugin Options (#3036)

* options

* add test

* Do not indent on TAB (#3039)

* keyboard tab

* remove import

* Fix 354663 (#3038)

* Fix 354663

* export the new function

* Fix Word Desktop paste case (#3034)

Co-authored-by: Jiuqing Song <jisong@microsoft.com>

* Add height property to table rows in paste tests and processor (#3045)

* Add height property to table rows in paste tests and processor

* Fix build

* Remove local change

* Fix A11y bug with table selection (#3041)

* Fix A11y bug with table selection

* Add comment

* Fix 341291 (#3046)

* Fix Word Desktop pasting when using Safari (#3047)

* Enhance paste functionality: support additional document types and extract HTML head content

* Fix paste source validations for Safari: update environment handling and improve document detection logic

* Add environment param back

* Prevent multiple event attachments for mousemove in SelectionPlugin (#3049)

* Prevent multiple event attachments for mousemove in SelectionPlugin

* Update packages/roosterjs-content-model-core/test/corePlugin/selection/SelectionPluginTest.ts

* Refactor mouse event handling in SelectionPlugin to ensure proper cleanup and re-attachment on mouseDown events

* Only paste text content of button (#3050)

* Enhance paste functionality: Update setProcessor call counts in tests and add pasteButtonProcessor unit tests

* Refactor pasteButtonProcessor: Enhance button element processing and add comprehensive unit tests

* Support table edit with logical root (#3048)

* Support table edit with logical root

* fix build and test

---------

Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>

* Bump to 9.29.0

* Fix broken code

---------

Co-authored-by: Jiuqing Song <jisong@microsoft.com>
Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>
Co-authored-by: Julia Roldi <87443959+juliaroldi@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: florian-msft <87671048+florian-msft@users.noreply.github.com>
JiuqingSong added a commit that referenced this pull request May 27, 2025
* Use FormatContainer to represent DIV with id (#3003)

* Fix #3005 (#3007)

* Fix a cache issue (#3006)

* Refactor getStyleMetadata to not rely on DomCreator and only use String handling (#3010)

* Refactor paste plugin to remove unused DOMCreator parameter and enhance style extraction logic

* fix test

* Change search string to lowercase

* Clean image edit when undo (#3015)

* undo image

* undo image

* undo image

* Add 'CustomCopyCut' experimental feature to fix some copy cut bugs (#3000)

* Add 'CustomCopyCut' experimental feature to enhance copy/cut behavior

* Implement pruneUnselectedModel utility for optimizing copy/paste behavior

* Try fix iuld

* Address comment and fix broken tests

* Revert unneeded change

* Refactor pruneUnselectedModel

---------

Co-authored-by: Jiuqing Song <jisong@microsoft.com>

* Demo site: Add preset content for undeleteable anchor (#3014)

Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>

* Revert "Refactor getStyleMetadata to not rely on DomCreator and only use Stri…" (#3020)

This reverts commit 5bbab35.

* Add API playground for createModelFromHTML (#3019)

* Add API playground for createModelFromHTML

* imporve

---------

Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>

* Do not copy div ID on Enter (#3011)

* wip

* insertCustom

* refactor

* formatKeys

* Add image hidden marker (#3021)

Instead of using a dataset to store the isEditing property, a hidden property is now used. To support this, get/set functions and the ImageMarkerFormat were introduced. The imageMarker property can now be accessed through the format property of the image.
This change eliminates the need to manually remove the dataset from the image element when extracting content from the DOM.

* Include ImageMetadata in FormatState (#3023)

* Support List Pasting from PowerPoint Desktop (#3012)

* Refactor paste parsers: add removeNegativeTextIndentParser and deprecatedBorderColorParser; update imports and constants for bullet list types

* Update packages/roosterjs-content-model-plugins/lib/paste/PowerPoint/processPastedContentFromPowerPoint.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor bullet list constants and improve format parser signatures

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Remove comments `<!--` and `-->` from styles and re apply fix for Word Desktop Pasting  (#3024)

* Update dependencies and enhance paste functionality by cleaning HTML comments in style tags

* Reapply "Refactor getStyleMetadata to not rely on DomCreator and only use Stri…" (#3020)

This reverts commit 32f47bf.

* Enhance cleanHtmlComments to handle both HTML comment formats in style tags

* Set original DOMPurify

* Update packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/getStyleMetadata.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Ensure headEndIndex is valid

* address comment

* Address comments

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Jiuqing Song <jisong@microsoft.com>

* insert link in the image (#3027)

When the image is selected, do not replace the image with the link, add the link to image segment.

* square (#3029)

Instead of using a square character, this change updates the square style to use the 'square' style.

* Normalize default format (#3028)

* Normalize default format

* improve

---------

Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>

* auto link (#3026)

* Add margin-inline-start to watermark styles for improved positioning (#3031)

* Allow queryContentModelBlocks to query blocks in entities (#3032)

* Allow queryContentModelBlocks to search children of entity

* Expect EditorContext instead

* Break out createEditorContextForEntity function into separate file and add tests

* Fix 353323: Keep indentation when start a list, and refactor (#3033)

* 353323

* fix build, add test

* improve

* Edit plugin Options (#3036)

* options

* add test

* Do not indent on TAB (#3039)

* keyboard tab

* remove import

* Fix 354663 (#3038)

* Fix 354663

* export the new function

* Fix Word Desktop paste case (#3034)

Co-authored-by: Jiuqing Song <jisong@microsoft.com>

* Add height property to table rows in paste tests and processor (#3045)

* Add height property to table rows in paste tests and processor

* Fix build

* Remove local change

* Fix A11y bug with table selection (#3041)

* Fix A11y bug with table selection

* Add comment

* Fix 341291 (#3046)

* Fix Word Desktop pasting when using Safari (#3047)

* Enhance paste functionality: support additional document types and extract HTML head content

* Fix paste source validations for Safari: update environment handling and improve document detection logic

* Add environment param back

* Prevent multiple event attachments for mousemove in SelectionPlugin (#3049)

* Prevent multiple event attachments for mousemove in SelectionPlugin

* Update packages/roosterjs-content-model-core/test/corePlugin/selection/SelectionPluginTest.ts

* Refactor mouse event handling in SelectionPlugin to ensure proper cleanup and re-attachment on mouseDown events

* Only paste text content of button (#3050)

* Enhance paste functionality: Update setProcessor call counts in tests and add pasteButtonProcessor unit tests

* Refactor pasteButtonProcessor: Enhance button element processing and add comprehensive unit tests

* Support table edit with logical root (#3048)

* Support table edit with logical root

* fix build and test

---------

Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>

* If font family already has single quote, keep it (#3055)

* 9.29.1

---------

Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>
Co-authored-by: Julia Roldi <87443959+juliaroldi@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: florian-msft <87671048+florian-msft@users.noreply.github.com>
BryanValverdeU added a commit that referenced this pull request May 28, 2025
* Use FormatContainer to represent DIV with id (#3003)

* Fix #3005 (#3007)

* Fix a cache issue (#3006)

* Refactor getStyleMetadata to not rely on DomCreator and only use String handling (#3010)

* Refactor paste plugin to remove unused DOMCreator parameter and enhance style extraction logic

* fix test

* Change search string to lowercase

* Clean image edit when undo (#3015)

* undo image

* undo image

* undo image

* Add 'CustomCopyCut' experimental feature to fix some copy cut bugs (#3000)

* Add 'CustomCopyCut' experimental feature to enhance copy/cut behavior

* Implement pruneUnselectedModel utility for optimizing copy/paste behavior

* Try fix iuld

* Address comment and fix broken tests

* Revert unneeded change

* Refactor pruneUnselectedModel

---------

Co-authored-by: Jiuqing Song <jisong@microsoft.com>

* Demo site: Add preset content for undeleteable anchor (#3014)

Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>

* Revert "Refactor getStyleMetadata to not rely on DomCreator and only use Stri…" (#3020)

This reverts commit 5bbab35.

* Add API playground for createModelFromHTML (#3019)

* Add API playground for createModelFromHTML

* imporve

---------

Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>

* Do not copy div ID on Enter (#3011)

* wip

* insertCustom

* refactor

* formatKeys

* Add image hidden marker (#3021)

Instead of using a dataset to store the isEditing property, a hidden property is now used. To support this, get/set functions and the ImageMarkerFormat were introduced. The imageMarker property can now be accessed through the format property of the image.
This change eliminates the need to manually remove the dataset from the image element when extracting content from the DOM.

* Include ImageMetadata in FormatState (#3023)

* Support List Pasting from PowerPoint Desktop (#3012)

* Refactor paste parsers: add removeNegativeTextIndentParser and deprecatedBorderColorParser; update imports and constants for bullet list types

* Update packages/roosterjs-content-model-plugins/lib/paste/PowerPoint/processPastedContentFromPowerPoint.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor bullet list constants and improve format parser signatures

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Remove comments `<!--` and `-->` from styles and re apply fix for Word Desktop Pasting  (#3024)

* Update dependencies and enhance paste functionality by cleaning HTML comments in style tags

* Reapply "Refactor getStyleMetadata to not rely on DomCreator and only use Stri…" (#3020)

This reverts commit 32f47bf.

* Enhance cleanHtmlComments to handle both HTML comment formats in style tags

* Set original DOMPurify

* Update packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/getStyleMetadata.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Ensure headEndIndex is valid

* address comment

* Address comments

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Jiuqing Song <jisong@microsoft.com>

* insert link in the image (#3027)

When the image is selected, do not replace the image with the link, add the link to image segment.

* square (#3029)

Instead of using a square character, this change updates the square style to use the 'square' style.

* Normalize default format (#3028)

* Normalize default format

* improve

---------

Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>

* auto link (#3026)

* Add margin-inline-start to watermark styles for improved positioning (#3031)

* Allow queryContentModelBlocks to query blocks in entities (#3032)

* Allow queryContentModelBlocks to search children of entity

* Expect EditorContext instead

* Break out createEditorContextForEntity function into separate file and add tests

* Fix 353323: Keep indentation when start a list, and refactor (#3033)

* 353323

* fix build, add test

* improve

* Edit plugin Options (#3036)

* options

* add test

* Do not indent on TAB (#3039)

* keyboard tab

* remove import

* Fix 354663 (#3038)

* Fix 354663

* export the new function

* Fix Word Desktop paste case (#3034)

Co-authored-by: Jiuqing Song <jisong@microsoft.com>

* Add height property to table rows in paste tests and processor (#3045)

* Add height property to table rows in paste tests and processor

* Fix build

* Remove local change

* Fix A11y bug with table selection (#3041)

* Fix A11y bug with table selection

* Add comment

* Fix 341291 (#3046)

* Fix Word Desktop pasting when using Safari (#3047)

* Enhance paste functionality: support additional document types and extract HTML head content

* Fix paste source validations for Safari: update environment handling and improve document detection logic

* Add environment param back

* Prevent multiple event attachments for mousemove in SelectionPlugin (#3049)

* Prevent multiple event attachments for mousemove in SelectionPlugin

* Update packages/roosterjs-content-model-core/test/corePlugin/selection/SelectionPluginTest.ts

* Refactor mouse event handling in SelectionPlugin to ensure proper cleanup and re-attachment on mouseDown events

* Only paste text content of button (#3050)

* Enhance paste functionality: Update setProcessor call counts in tests and add pasteButtonProcessor unit tests

* Refactor pasteButtonProcessor: Enhance button element processing and add comprehensive unit tests

* Support table edit with logical root (#3048)

* Support table edit with logical root

* fix build and test

---------

Co-authored-by: Bryan Valverde U <bvalverde@microsoft.com>

* If font family already has single quote, keep it (#3055)

* Fix announcing in lists (#3058)

* Fix announcing in lists

* fix tests in FF

* Add role="presentation" to generic role elements in list items for better screen reader support

* Bump roosterjs-content-model-dom version to 9.29.2

---------

Co-authored-by: Jiuqing Song <jisong@microsoft.com>
Co-authored-by: Julia Roldi <87443959+juliaroldi@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: florian-msft <87671048+florian-msft@users.noreply.github.com>
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.

3 participants