Skip to content
Snippets Groups Projects
Commit 4e7f52ca authored by chris's avatar chris
Browse files

headings Active

parent 7e55de78
No related branches found
No related tags found
1 merge request!172Block level active
......@@ -19,7 +19,7 @@ const Button = ({ view = {}, item }) => {
run(state, dispatch);
};
const isActive = active && active(state);
const isActive = active && active(state, activeViewId);
const isDisabled =
enable && !enable(state) && !(select && select(state, activeViewId));
......
......@@ -19,8 +19,17 @@ class Heading1 extends Tools {
}
get active() {
return state => {
return Commands.blockActive(state.config.schema.nodes.heading, {
return (state, activeViewId) => {
let isActive = true;
if (activeViewId !== 'main') return false;
const { from, to } = state.selection;
state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.name === 'list_item') {
isActive = false;
}
});
if (!isActive) return false;
return !Commands.setBlockType(state.config.schema.nodes.heading, {
level: 1,
})(state);
};
......
......@@ -19,8 +19,17 @@ class Heading2 extends Tools {
}
get active() {
return state => {
return Commands.blockActive(state.config.schema.nodes.heading, {
return (state, activeViewId) => {
let isActive = true;
if (activeViewId !== 'main') return false;
const { from, to } = state.selection;
state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.name === 'list_item') {
isActive = false;
}
});
if (!isActive) return false;
return !Commands.setBlockType(state.config.schema.nodes.heading, {
level: 2,
})(state);
};
......
......@@ -19,8 +19,17 @@ class Heading3 extends Tools {
}
get active() {
return state => {
return Commands.blockActive(state.config.schema.nodes.heading, {
return (state, activeViewId) => {
let isActive = true;
if (activeViewId !== 'main') return false;
const { from, to } = state.selection;
state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.name === 'list_item') {
isActive = false;
}
});
if (!isActive) return false;
return !Commands.setBlockType(state.config.schema.nodes.heading, {
level: 3,
})(state);
};
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment