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

Issue/3336 repeated style #3337

Merged
merged 4 commits into from
Jun 10, 2022
Merged

Conversation

Dora1604
Copy link
Contributor

@Dora1604 Dora1604 commented Apr 14, 2021

Fix issue #3336 with repeated styles

This pull request fixes issue #3336.

When calling getFormat() and finding multiple style value, there were two options to solve this issue:

  • Adding already existing style to style array which means it is in an array twice
  • Skipping and continue looping

I decided to go with second option because it fits more with the existing code.

Code

In combineFormats function, I changed this code block:

if (combined[name].indexOf(formats[name]) < 0) {
  merged[name] = combined[name].concat([formats[name]]);
} else {
  // Here is the change
  merged[name] = combined[name];
}

The whole function:

function combineFormats(formats, combined) {
  return Object.keys(combined).reduce((merged, name) => {
    if (formats[name] == null) return merged;
    if (combined[name] === formats[name]) {
      merged[name] = combined[name];
    } else if (Array.isArray(combined[name])) {
      if (combined[name].indexOf(formats[name]) < 0) {
        merged[name] = combined[name].concat([formats[name]]);
      } else {
        // If style already exists continue looping but do not lose other styles
        merged[name] = combined[name];
      }
    } else {
      merged[name] = [combined[name], formats[name]];
    }
    return merged;
  }, {});
}

If you have any questions, I am opened to discussion. I hope you get to merge this pull request. Let me know if it is good. Thanks!

@jhchen jhchen merged commit 2e138a0 into slab:develop Jun 10, 2022
@jhchen
Copy link
Member

jhchen commented Jun 10, 2022

Thanks!

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.

None yet

2 participants