mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-07 16:04:19 +01:00
📱 点击底部键盘不弹起
This commit is contained in:
parent
7d1c310f89
commit
bbf4faf496
1 changed files with 49 additions and 51 deletions
|
|
@ -128,60 +128,58 @@ export const initUI = (protyle: IProtyle) => {
|
|||
(!event.target.classList.contains("protyle-content") && !event.target.classList.contains("protyle-wysiwyg"))) {
|
||||
return;
|
||||
}
|
||||
// 选中最后一个块末尾点击底部时,range 会有值,需等待
|
||||
setTimeout(() => {
|
||||
// 选中文本禁止添加空块 https://github.com/siyuan-note/siyuan/issues/13905
|
||||
if (window.getSelection().rangeCount > 0) {
|
||||
const currentRange = window.getSelection().getRangeAt(0);
|
||||
if (currentRange.toString() !== "" && protyle.wysiwyg.element.contains(currentRange.startContainer)) {
|
||||
return;
|
||||
}
|
||||
// https://github.com/siyuan-note/siyuan/issues/14190 选中最后一个块末尾点击底部时,range 会有值,需使用 setTimeout,最新测试无需 setTimeout 了,且会影响移动端键盘弹起故移除
|
||||
// 选中文本禁止添加空块 https://github.com/siyuan-note/siyuan/issues/13905
|
||||
if (window.getSelection().rangeCount > 0) {
|
||||
const currentRange = window.getSelection().getRangeAt(0);
|
||||
if (currentRange.toString() !== "" && protyle.wysiwyg.element.contains(currentRange.startContainer)) {
|
||||
return;
|
||||
}
|
||||
const lastElement = protyle.wysiwyg.element.lastElementChild;
|
||||
const lastRect = lastElement.getBoundingClientRect();
|
||||
const range = document.createRange();
|
||||
if (event.y > lastRect.bottom) {
|
||||
const lastEditElement = getContenteditableElement(getLastBlock(lastElement));
|
||||
if (!protyle.options.click.preventInsetEmptyBlock && (
|
||||
!lastEditElement ||
|
||||
(lastElement.getAttribute("data-type") !== "NodeParagraph" && protyle.wysiwyg.element.getAttribute("data-doc-type") !== "NodeListItem") ||
|
||||
(lastElement.getAttribute("data-type") === "NodeParagraph" && getContenteditableElement(lastEditElement).innerHTML !== ""))
|
||||
) {
|
||||
let emptyElement: Element;
|
||||
if (lastElement.getAttribute("data-type") === "NodeHeading" && lastElement.getAttribute("fold") === "1") {
|
||||
emptyElement = genHeadingElement(lastElement) as Element;
|
||||
} else {
|
||||
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 lastElement = protyle.wysiwyg.element.lastElementChild;
|
||||
const lastRect = lastElement.getBoundingClientRect();
|
||||
const range = document.createRange();
|
||||
if (event.y > lastRect.bottom) {
|
||||
const lastEditElement = getContenteditableElement(getLastBlock(lastElement));
|
||||
if (!protyle.options.click.preventInsetEmptyBlock && (
|
||||
!lastEditElement ||
|
||||
(lastElement.getAttribute("data-type") !== "NodeParagraph" && protyle.wysiwyg.element.getAttribute("data-doc-type") !== "NodeListItem") ||
|
||||
(lastElement.getAttribute("data-type") === "NodeParagraph" && getContenteditableElement(lastEditElement).innerHTML !== ""))
|
||||
) {
|
||||
let emptyElement: Element;
|
||||
if (lastElement.getAttribute("data-type") === "NodeHeading" && lastElement.getAttribute("fold") === "1") {
|
||||
emptyElement = genHeadingElement(lastElement) as Element;
|
||||
} else {
|
||||
emptyElement = genEmptyElement(false, false);
|
||||
}
|
||||
protyle.toolbar.range = range;
|
||||
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);
|
||||
}
|
||||
});
|
||||
protyle.toolbar.range = range;
|
||||
}
|
||||
});
|
||||
let overAttr = false;
|
||||
const isTouch = isTouchDevice();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue