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

Merge Link & Image Format when using MergeModel #2681

Merged
merged 9 commits into from
Jun 6, 2024

Conversation

BryanValverdeU
Copy link
Contributor

@BryanValverdeU BryanValverdeU commented Jun 4, 2024

Add functionality to merge the link format. So we can successfully merge the target and source styles on paste if the option to merge style is chosen.

Also fix for images, as some formatting like width was getting lost when pasting with mergeFormat option.

Copy the link in this pen and paste and merge format:
https://codepen.io/Bryanvalverdeu/pen/ExzmOKb

Before
image

After
image

@BryanValverdeU BryanValverdeU changed the title Merge Link Format when using MergeModel Merge Link & Image Format when using MergeModel Jun 5, 2024
function getFormatWithoutSegmentFormat(
sourceFormat: ContentModelSegmentFormat
): ContentModelSegmentFormat {
const resultFormat = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we just simply copy the format that we want to copy, but not copy all then delete others?

I feel the format we want to keep is less than the ones we want to remove

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or, if we need to copy everything other than segment format, you can do like this:

  1. add a object to contains all properties of segment:
// An object to provide keys of required properties of segment format, the do NOT use any of its values
const requiredEmptySegmentFormat: Required<ContentModelSegmentFormat> = {
  fontFamily: null!,
  ...
}
  1. When copy format, delete format with keys of this object
const format = { ... }
getObjectKeys(requiredEmptySegmentFormat).forEach(key => delete format[key]);

So that if we add some new property to segment format in the future, we can still take care of them here since it will break the build.

Copy link
Contributor Author

@BryanValverdeU BryanValverdeU Jun 5, 2024

Choose a reason for hiding this comment

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

Or, if we need to copy everything other than segment format, you can do like this:

  1. add a object to contains all properties of segment:
// An object to provide keys of required properties of segment format, the do NOT use any of its values
const requiredEmptySegmentFormat: Required<ContentModelSegmentFormat> = {
  fontFamily: null!,
  ...
}
  1. When copy format, delete format with keys of this object
const format = { ... }
getObjectKeys(requiredEmptySegmentFormat).forEach(key => delete format[key]);

So that if we add some new property to segment format in the future, we can still take care of them here since it will break the build.

This looks better, I agree. Changing this.

The problem I saw with Copying only what we need is that ContentModelHyperlinkFormat and ContentModelImageFormat contain a lot more properties, so I thought removing the unneeded properties would be better.
And also in case there is a customized process/applier so we dont remove other styles.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, makes sense

@BryanValverdeU BryanValverdeU merged commit f8a23bb into master Jun 6, 2024
7 checks passed
BryanValverdeU added a commit that referenced this pull request Jun 6, 2024
* mergeLinkFormat

* Also fix for images

* remove unneeded changes

* Remove more unneeded changes

* Address comment

* nit

---------

Co-authored-by: Jiuqing Song <jisong@microsoft.com>
BryanValverdeU added a commit that referenced this pull request Jun 6, 2024
* Merge Link & Image Format when using MergeModel (#2681)

* mergeLinkFormat

* Also fix for images

* remove unneeded changes

* Remove more unneeded changes

* Address comment

* nit

---------

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

* update versions

* Merge pull request #2684 from microsoft/u/juliaroldi/trigger-auto-format

Auto format trigger

---------

Co-authored-by: Jiuqing Song <jisong@microsoft.com>
Co-authored-by: Julia Roldi <87443959+juliaroldi@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.

2 participants