mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-03 04:50:59 +08:00
This commit is contained in:
parent
9945ad7a7a
commit
1e62853195
@ -128,48 +128,51 @@ export const initUI = (protyle: IProtyle) => {
|
|||||||
(!event.target.classList.contains("protyle-content") && !event.target.classList.contains("protyle-wysiwyg"))) {
|
(!event.target.classList.contains("protyle-content") && !event.target.classList.contains("protyle-wysiwyg"))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 选中文本禁止添加空块 https://github.com/siyuan-note/siyuan/issues/13905
|
// 选中最后一个块末尾点击底部时,range 会有值,需等待
|
||||||
if (window.getSelection().rangeCount > 0) {
|
setTimeout(() => {
|
||||||
const currentRange = window.getSelection().getRangeAt(0);
|
// 选中文本禁止添加空块 https://github.com/siyuan-note/siyuan/issues/13905
|
||||||
if (currentRange.toString() !== "" && protyle.wysiwyg.element.contains(currentRange.startContainer)) {
|
if (window.getSelection().rangeCount > 0) {
|
||||||
return;
|
const currentRange = window.getSelection().getRangeAt(0);
|
||||||
}
|
if (currentRange.toString() !== "" && protyle.wysiwyg.element.contains(currentRange.startContainer)) {
|
||||||
}
|
return;
|
||||||
const lastRect = protyle.wysiwyg.element.lastElementChild.getBoundingClientRect();
|
|
||||||
const range = document.createRange();
|
|
||||||
if (event.y > lastRect.bottom) {
|
|
||||||
const lastEditElement = getContenteditableElement(getLastBlock(protyle.wysiwyg.element.lastElementChild));
|
|
||||||
if (!lastEditElement ||
|
|
||||||
(protyle.wysiwyg.element.lastElementChild.getAttribute("data-type") !== "NodeParagraph" && protyle.wysiwyg.element.getAttribute("data-doc-type") !== "NodeListItem" && !protyle.options.backlinkData) ||
|
|
||||||
(protyle.wysiwyg.element.lastElementChild.getAttribute("data-type") === "NodeParagraph" && getContenteditableElement(lastEditElement).innerHTML !== "")) {
|
|
||||||
const emptyElement = genEmptyElement(false, false);
|
|
||||||
protyle.wysiwyg.element.insertAdjacentElement("beforeend", emptyElement);
|
|
||||||
transaction(protyle, [{
|
|
||||||
action: "insert",
|
|
||||||
data: emptyElement.outerHTML,
|
|
||||||
id: emptyElement.getAttribute("data-node-id"),
|
|
||||||
previousID: emptyElement.previousElementSibling.getAttribute("data-node-id"),
|
|
||||||
parentID: protyle.block.parentID
|
|
||||||
}], [{
|
|
||||||
action: "delete",
|
|
||||||
id: emptyElement.getAttribute("data-node-id")
|
|
||||||
}]);
|
|
||||||
const emptyEditElement = getContenteditableElement(emptyElement) as HTMLInputElement;
|
|
||||||
range.selectNodeContents(emptyEditElement);
|
|
||||||
range.collapse(true);
|
|
||||||
focusByRange(range);
|
|
||||||
// 需等待 range 更新再次进行渲染
|
|
||||||
if (protyle.options.render.breadcrumb) {
|
|
||||||
setTimeout(() => {
|
|
||||||
protyle.breadcrumb.render(protyle);
|
|
||||||
}, Constants.TIMEOUT_TRANSITION);
|
|
||||||
}
|
}
|
||||||
} else if (lastEditElement) {
|
|
||||||
range.selectNodeContents(lastEditElement);
|
|
||||||
range.collapse(false);
|
|
||||||
focusByRange(range);
|
|
||||||
}
|
}
|
||||||
}
|
const lastRect = protyle.wysiwyg.element.lastElementChild.getBoundingClientRect();
|
||||||
|
const range = document.createRange();
|
||||||
|
if (event.y > lastRect.bottom) {
|
||||||
|
const lastEditElement = getContenteditableElement(getLastBlock(protyle.wysiwyg.element.lastElementChild));
|
||||||
|
if (!lastEditElement ||
|
||||||
|
(protyle.wysiwyg.element.lastElementChild.getAttribute("data-type") !== "NodeParagraph" && protyle.wysiwyg.element.getAttribute("data-doc-type") !== "NodeListItem" && !protyle.options.backlinkData) ||
|
||||||
|
(protyle.wysiwyg.element.lastElementChild.getAttribute("data-type") === "NodeParagraph" && getContenteditableElement(lastEditElement).innerHTML !== "")) {
|
||||||
|
const emptyElement = genEmptyElement(false, false);
|
||||||
|
protyle.wysiwyg.element.insertAdjacentElement("beforeend", emptyElement);
|
||||||
|
transaction(protyle, [{
|
||||||
|
action: "insert",
|
||||||
|
data: emptyElement.outerHTML,
|
||||||
|
id: emptyElement.getAttribute("data-node-id"),
|
||||||
|
previousID: emptyElement.previousElementSibling.getAttribute("data-node-id"),
|
||||||
|
parentID: protyle.block.parentID
|
||||||
|
}], [{
|
||||||
|
action: "delete",
|
||||||
|
id: emptyElement.getAttribute("data-node-id")
|
||||||
|
}]);
|
||||||
|
const emptyEditElement = getContenteditableElement(emptyElement) as HTMLInputElement;
|
||||||
|
range.selectNodeContents(emptyEditElement);
|
||||||
|
range.collapse(true);
|
||||||
|
focusByRange(range);
|
||||||
|
// 需等待 range 更新再次进行渲染
|
||||||
|
if (protyle.options.render.breadcrumb) {
|
||||||
|
setTimeout(() => {
|
||||||
|
protyle.breadcrumb.render(protyle);
|
||||||
|
}, Constants.TIMEOUT_TRANSITION);
|
||||||
|
}
|
||||||
|
} else if (lastEditElement) {
|
||||||
|
range.selectNodeContents(lastEditElement);
|
||||||
|
range.collapse(false);
|
||||||
|
focusByRange(range);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
let overAttr = false;
|
let overAttr = false;
|
||||||
protyle.element.addEventListener("mouseover", (event: KeyboardEvent & { target: HTMLElement }) => {
|
protyle.element.addEventListener("mouseover", (event: KeyboardEvent & { target: HTMLElement }) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user