This commit is contained in:
parent
b11417d725
commit
a129c25c2e
2 changed files with 42 additions and 12 deletions
|
@ -1365,7 +1365,16 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
if (matchHotKey(window.siyuan.config.keymap.editor.list.outdent.custom, event)) {
|
||||
const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
|
||||
if (selectElements.length > 0) {
|
||||
if (selectElements[0].getAttribute("data-type") === "NodeListItem") {
|
||||
let isContinuous = true;
|
||||
selectElements.forEach((item, index) => {
|
||||
if (item.nextElementSibling && selectElements[index + 1]) {
|
||||
if (!selectElements[index + 1].isSameNode(item.nextElementSibling)) {
|
||||
isContinuous = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (isContinuous &&
|
||||
(selectElements[0].classList.contains("li") || selectElements[0].parentElement.classList.contains("li"))) {
|
||||
listOutdent(protyle, Array.from(selectElements), range);
|
||||
}
|
||||
event.preventDefault();
|
||||
|
@ -1382,7 +1391,16 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
if (matchHotKey(window.siyuan.config.keymap.editor.list.indent.custom, event)) {
|
||||
const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
|
||||
if (selectElements.length > 0) {
|
||||
if (selectElements[0].getAttribute("data-type") === "NodeListItem") {
|
||||
let isContinuous = true;
|
||||
selectElements.forEach((item, index) => {
|
||||
if (item.nextElementSibling && selectElements[index + 1]) {
|
||||
if (!selectElements[index + 1].isSameNode(item.nextElementSibling)) {
|
||||
isContinuous = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (isContinuous &&
|
||||
(selectElements[0].classList.contains("li") || selectElements[0].parentElement.classList.contains("li"))) {
|
||||
listIndent(protyle, Array.from(selectElements), range);
|
||||
}
|
||||
event.preventDefault();
|
||||
|
|
|
@ -76,16 +76,23 @@ export const addSubList = (protyle: IProtyle, nodeElement: Element, range: Range
|
|||
};
|
||||
|
||||
export const listIndent = (protyle: IProtyle, liItemElements: Element[], range: Range) => {
|
||||
liItemElements.forEach(item => {
|
||||
item.removeAttribute("select-start");
|
||||
item.removeAttribute("select-end");
|
||||
});
|
||||
if (!liItemElements[0].classList.contains("li")) {
|
||||
if (liItemElements[0].parentElement.childElementCount === liItemElements.length + 2) {
|
||||
liItemElements = [liItemElements[0].parentElement];
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const previousElement = liItemElements[0].previousElementSibling as HTMLElement;
|
||||
if (!previousElement) {
|
||||
return;
|
||||
}
|
||||
range.collapse(false);
|
||||
range.insertNode(document.createElement("wbr"));
|
||||
liItemElements.forEach(item => {
|
||||
item.removeAttribute("select-start");
|
||||
item.removeAttribute("select-end");
|
||||
});
|
||||
const html = previousElement.parentElement.outerHTML;
|
||||
if (previousElement.lastElementChild.previousElementSibling.getAttribute("data-type") === "NodeList") {
|
||||
// 上一个列表的最后一项为子列表
|
||||
|
@ -319,6 +326,17 @@ export const breakList = (protyle: IProtyle, blockElement: Element, range: Range
|
|||
* @param deleteElement 末尾反向删除时才会传入
|
||||
*/
|
||||
export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range: Range, isDelete = false, deleteElement?: Element) => {
|
||||
liItemElements.forEach(item => {
|
||||
item.removeAttribute("select-start");
|
||||
item.removeAttribute("select-end");
|
||||
});
|
||||
if (!liItemElements[0].classList.contains("li")) {
|
||||
if (liItemElements[0].parentElement.childElementCount === liItemElements.length + 2) {
|
||||
liItemElements = [liItemElements[0].parentElement];
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const liElement = liItemElements[0].parentElement;
|
||||
const liId = liElement.getAttribute("data-node-id");
|
||||
if (!liId) {
|
||||
|
@ -347,8 +365,6 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
|
|||
let nextElement = liItemElements[liItemElements.length - 1].nextElementSibling;
|
||||
let lastBlockElement = liItemElements[liItemElements.length - 1].lastElementChild.previousElementSibling;
|
||||
liItemElements.forEach(item => {
|
||||
item.removeAttribute("select-start");
|
||||
item.removeAttribute("select-end");
|
||||
Array.from(item.children).forEach((blockElement, index) => {
|
||||
const id = blockElement.getAttribute("data-node-id");
|
||||
if (!id) {
|
||||
|
@ -504,10 +520,6 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
|
|||
const doOperations: IOperation[] = [];
|
||||
const undoOperations: IOperation[] = [];
|
||||
const previousID = liItemElements[0].previousElementSibling?.getAttribute("data-node-id");
|
||||
liItemElements.forEach(item => {
|
||||
item.removeAttribute("select-start");
|
||||
item.removeAttribute("select-end");
|
||||
});
|
||||
let startIndex;
|
||||
if (!liItemElements[0].previousElementSibling && liElement.getAttribute("data-subtype") === "o") {
|
||||
startIndex = parseInt(liItemElements[0].getAttribute("data-marker"));
|
||||
|
|
Loading…
Add table
Reference in a new issue