🚨
This commit is contained in:
parent
829b7d40d4
commit
6b4af527e1
4 changed files with 26 additions and 26 deletions
|
@ -727,7 +727,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
|||
const previous = hasPreviousSibling(range.startContainer);
|
||||
if (previous && previous.nodeType !== 3 && (previous as HTMLElement).classList.contains("img")) {
|
||||
if (!hasNextSibling(previous)) {
|
||||
range.insertNode(document.createTextNode(Constants.ZWSP))
|
||||
range.insertNode(document.createTextNode(Constants.ZWSP));
|
||||
range.collapse(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -237,33 +237,33 @@ export class Toolbar {
|
|||
return;
|
||||
}
|
||||
const rangeTypes = this.getCurrentType();
|
||||
let previousElement: Element
|
||||
let nextElement: Element
|
||||
let previousIndex: number
|
||||
let nextIndex: number
|
||||
const previousSibling = hasPreviousSibling(this.range.startContainer)
|
||||
let previousElement: Element;
|
||||
let nextElement: Element;
|
||||
let previousIndex: number;
|
||||
let nextIndex: number;
|
||||
const previousSibling = hasPreviousSibling(this.range.startContainer);
|
||||
if (!["DIV", "TD", "TH"].includes(this.range.startContainer.parentElement.tagName)) {
|
||||
if (this.range.startOffset === 0 && !previousSibling) {
|
||||
previousElement = this.range.startContainer.parentElement.previousSibling as Element
|
||||
this.range.setStartBefore(this.range.startContainer.parentElement)
|
||||
previousElement = this.range.startContainer.parentElement.previousSibling as Element;
|
||||
this.range.setStartBefore(this.range.startContainer.parentElement);
|
||||
} else {
|
||||
previousElement = this.range.startContainer.parentElement
|
||||
previousElement = this.range.startContainer.parentElement;
|
||||
}
|
||||
} else if (previousSibling && previousSibling.nodeType !== 3 && this.range.startOffset === 0) {
|
||||
// **aaa**bbb 选中 bbb 加粗
|
||||
previousElement = previousSibling as Element
|
||||
previousElement = previousSibling as Element;
|
||||
}
|
||||
const nextSibling = hasNextSibling(this.range.endContainer)
|
||||
const nextSibling = hasNextSibling(this.range.endContainer);
|
||||
if (!["DIV", "TD", "TH"].includes(this.range.endContainer.parentElement.tagName)) {
|
||||
if (this.range.endOffset === this.range.endContainer.textContent.length && !nextSibling) {
|
||||
nextElement = this.range.endContainer.parentElement.nextSibling as Element
|
||||
this.range.setEndAfter(this.range.endContainer.parentElement)
|
||||
nextElement = this.range.endContainer.parentElement.nextSibling as Element;
|
||||
this.range.setEndAfter(this.range.endContainer.parentElement);
|
||||
} else {
|
||||
nextElement = this.range.endContainer.parentElement
|
||||
nextElement = this.range.endContainer.parentElement;
|
||||
}
|
||||
} else if (nextSibling && nextSibling.nodeType !== 3 && this.range.endOffset === this.range.endContainer.textContent.length) {
|
||||
// aaa**bbb** 选中 aaa 加粗
|
||||
nextElement = nextSibling as Element
|
||||
nextElement = nextSibling as Element;
|
||||
}
|
||||
const wbrElement = document.createElement("wbr");
|
||||
this.range.insertNode(wbrElement);
|
||||
|
@ -298,9 +298,9 @@ export class Toolbar {
|
|||
types.find((itemType, index) => {
|
||||
if (type === itemType) {
|
||||
types.splice(index, 1);
|
||||
return true
|
||||
return true;
|
||||
}
|
||||
})
|
||||
});
|
||||
if (types.length === 0) {
|
||||
newNodes.push(document.createTextNode(item.textContent));
|
||||
} else {
|
||||
|
@ -340,7 +340,7 @@ export class Toolbar {
|
|||
} else {
|
||||
let types = (item.getAttribute("data-type") || "").split(" ");
|
||||
types.push(type);
|
||||
types = [...new Set(types)]
|
||||
types = [...new Set(types)];
|
||||
if (index === 0 && previousElement && previousElement.nodeType !== 3 && isArrayEqual(types, previousElement.getAttribute("data-type").split(" "))) {
|
||||
previousIndex = previousElement.textContent.length;
|
||||
previousElement.innerHTML = previousElement.innerHTML + item.innerHTML;
|
||||
|
@ -373,7 +373,7 @@ export class Toolbar {
|
|||
if (nextIndex) {
|
||||
this.range.setEnd(nextElement.lastChild, nextIndex);
|
||||
} else if (newNodes.length > 0) {
|
||||
const lastNewNode = newNodes[newNodes.length - 1]
|
||||
const lastNewNode = newNodes[newNodes.length - 1];
|
||||
if (lastNewNode.lastChild) {
|
||||
this.range.setEnd(lastNewNode.lastChild, lastNewNode.lastChild.textContent.length);
|
||||
} else {
|
||||
|
|
|
@ -305,14 +305,14 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
|
|||
}
|
||||
if (operation.action === "updateAttrs") { // 调用接口才推送
|
||||
protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach(item => {
|
||||
const data = operation.data as any
|
||||
const data = operation.data as any;
|
||||
Object.keys(data.old).forEach(key => {
|
||||
item.removeAttribute(key)
|
||||
})
|
||||
let nodeAttrHTML = ""
|
||||
item.removeAttribute(key);
|
||||
});
|
||||
let nodeAttrHTML = "";
|
||||
Object.keys(data.new).forEach(key => {
|
||||
item.setAttribute(key, data.new[key]);
|
||||
const escapeHTML = data.new[key]
|
||||
const escapeHTML = data.new[key];
|
||||
if (key === "bookmark") {
|
||||
nodeAttrHTML += `<div class="protyle-attr--bookmark">${escapeHTML}</div>`;
|
||||
} else if (key === "name") {
|
||||
|
@ -322,7 +322,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
|
|||
} else if (key === "memo") {
|
||||
nodeAttrHTML += `<div class="protyle-attr--memo b3-tooltips b3-tooltips__sw" aria-label="${escapeHTML}"><svg><use xlink:href="#iconM"></use></svg></div>`;
|
||||
}
|
||||
})
|
||||
});
|
||||
const refElement = item.lastElementChild.querySelector(".protyle-attr--refcount");
|
||||
if (refElement) {
|
||||
nodeAttrHTML += refElement.outerHTML;
|
||||
|
|
|
@ -4,7 +4,7 @@ export const isMobile = () => {
|
|||
|
||||
export const isArrayEqual = (arr1: string[], arr2: string[]) => {
|
||||
return arr1.length === arr2.length && arr1.every((item) => arr2.includes(item));
|
||||
}
|
||||
};
|
||||
|
||||
export const getRandom = (min: number, max: number) => {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值,含最小值
|
||||
|
|
Loading…
Add table
Reference in a new issue