Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy-markers clipboard mechanism refactor #16005

Merged
merged 24 commits into from
Mar 25, 2024
Merged

Copy-markers clipboard mechanism refactor #16005

merged 24 commits into from
Mar 25, 2024

Conversation

Mati365
Copy link
Member

@Mati365 Mati365 commented Mar 8, 2024

Suggested merge commit message (convention)

Fix (clipboard): By default, do not copy markers if they are partially selected.
Tests (clipboard): Add missing tests for pasting duplicated markers in table plugin.
Internal (clipboard): Add duplicateOnPaste to marker clipboard configuration. Closes #15966. Related to #15968.
Fix (engine): Do not trigger change:data on copy with markers. Closes #15943.
Fix (clipboard): Importing from Word crashes when the document contains suggestions.

Fixes https://github.com/cksource/ckeditor5-commercial/issues/6053.
Closes https://github.com/cksource/ckeditor5-commercial/issues/6056.

@Mati365 Mati365 changed the title Differ changes Do not fire change:data when copy with markers Mar 8, 2024
@Mati365 Mati365 changed the title Do not fire change:data when copy with markers Copy-markers clipboard mechanism refactor Mar 12, 2024
@Mati365 Mati365 changed the base branch from ck/6053 to master March 12, 2024 08:42
@Mati365 Mati365 force-pushed the ck/15943 branch 2 times, most recently from c6efece to 803f623 Compare March 13, 2024 10:19
range
} ) )
.filter( marker => this._canPerformMarkerClipboardAction( marker.name, action ) );
return entries.flatMap( ( [ markerName, range ] ): Array<CopyableMarker> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see that you're using flatMap, presumably to eliminate empty values. However, using flatMap solely for this purpose might be somewhat convoluted. Instead, opting for a for-loop approach can offer simplicity and clarity in code comprehension. By directly iterating over the data and modifying the result array within the loop, we avoid the overhead of creating additional result arrays, which occurs when using flatMap. This direct approach can lead to an easier understanding of the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

@DawidKossowski It's a discussion between functional (immutable) and imperative (mutable) approach. From my point of the view, the first one is much easier to debug because it disallows programmer to modify previously added items and allows to easily chain new transformers on already mapped array. In this particular case, performance is not even an issue because it'll work exactly the same for arrays with even ~5000 items.

Copy link
Contributor

@DawidKossowski DawidKossowski Mar 14, 2024

Choose a reason for hiding this comment

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

I have nothing against functional programming, but we simply don't use such practices in our project.

@niegowski WDYT?

Edit: I've also checked the performance, and it appears that flatMap is slower by ~80% compared to the for-loop for these operations. However, as Mateusz mentioned, given the scale of the data we're working with, this difference is marginal (maximum a few milliseconds).

Copy link
Contributor

@DawidKossowski DawidKossowski left a comment

Choose a reason for hiding this comment

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

LGTM. There is one open discussion, but I don't think it is a blocker, and we can go with the current approach as well. Anyway, waiting for @niegowski final check.

@DawidKossowski DawidKossowski merged commit 39a7791 into master Mar 25, 2024
6 checks passed
@DawidKossowski DawidKossowski deleted the ck/15943 branch March 25, 2024 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants