1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-15 12:41:52 +03:00

Got alignment buttons barely working for paragraphs

This commit is contained in:
Dan Brown
2022-01-11 18:58:24 +00:00
parent 4e5153d372
commit 6744ab2ff9
5 changed files with 120 additions and 6 deletions

View File

@ -0,0 +1,38 @@
export function setBlockAttr(attrName, attrValue) {
return function (state, dispatch) {
const ref = state.selection;
const from = ref.from;
const to = ref.to;
let applicable = false;
state.doc.nodesBetween(from, to, function (node, pos) {
if (applicable) {
return false
}
if (!node.isTextblock || node.attrs[attrName] === attrValue) {
return
}
applicable = node.attrs[attrName] !== undefined;
});
if (!applicable) {
return false
}
if (dispatch) {
const tr = state.tr;
tr.doc.nodesBetween(from, to, function (node, pos) {
const nodeAttrs = Object.assign({}, node.attrs);
if (node.attrs[attrName] !== undefined) {
nodeAttrs[attrName] = attrValue;
tr.setBlockType(pos, pos+1, node.type, nodeAttrs)
}
});
dispatch(tr);
}
return true
}
}