-
Notifications
You must be signed in to change notification settings - Fork 166
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
Conversation
function getFormatWithoutSegmentFormat( | ||
sourceFormat: ContentModelSegmentFormat | ||
): ContentModelSegmentFormat { | ||
const resultFormat = { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
- 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!,
...
}
- 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.
There was a problem hiding this comment.
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:
- 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!, ... }
- 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, makes sense
* mergeLinkFormat * Also fix for images * remove unneeded changes * Remove more unneeded changes * Address comment * nit --------- Co-authored-by: Jiuqing Song <jisong@microsoft.com>
* 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>
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
After