Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Improve logic
Browse files Browse the repository at this point in the history
  • Loading branch information
silviubogan committed Sep 1, 2020
1 parent 3d21fd1 commit 9652c0c
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/editor/plugins/StyleMenu/StyleMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,28 +181,36 @@ const StylingsButton = (props) => {
};
}}
onChange={(selItem, meta) => {
console.log('meta', meta);
// console.log('meta', meta);

if (selItem.length === 0) {
toggleBlockStyle(editor, undefined);
toggleInlineStyle(editor, undefined);
return;
}

// TODO: compose separate style names to make the final className
// value (currently a single style name is inside the className of the
// selection or the block)
for (const item of selItem) {
if (isBlockStyleActive(editor, item.value)) {
toggleBlockStyle(editor, item.value);
} else if (isInlineStyleActive(editor, item.value)) {
toggleInlineStyle(editor, item.value);
}
for (const item of rawOpts) {
const isRequested = selItem.includes(item);
const isActive =
isBlockStyleActive(editor, item.value) ||
isInlineStyleActive(editor, item.value);

if (item.isBlock) {
toggleBlockStyle(editor, item.value);
} else {
toggleInlineStyle(editor, item.value);
if (isRequested && isActive) {
// nothing to do
} else if (isRequested && !isActive) {
if (item.isBlock && !isBlockStyleActive(editor, item.value)) {
toggleBlockStyle(editor, item.value);
} else if (
!item.isBlock &&
!isInlineStyleActive(editor, item.value)
) {
toggleInlineStyle(editor, item.value);
}
} else if (!isRequested && isActive) {
if (item.isBlock && !isBlockStyleActive(editor, item.value)) {
toggleBlockStyle(editor, item.value);
} else if (
!item.isBlock &&
!isInlineStyleActive(editor, item.value)
) {
toggleInlineStyle(editor, item.value);
}
} else if (!isRequested && !isActive) {
// nothing to do
}
}
}}
Expand Down

0 comments on commit 9652c0c

Please sign in to comment.