This commit is contained in:
Vanessa 2023-04-05 17:16:24 +08:00
parent 67a0efee1b
commit 4324817ed1
3 changed files with 18 additions and 14 deletions

View file

@ -5,7 +5,6 @@ import {Constants} from "../constants";
import {fetchPost} from "../util/fetch";
import {disabledProtyle, onGet} from "../protyle/util/onGet";
import {addLoading} from "../protyle/ui/initUI";
import {focusBlock} from "../protyle/util/selection";
import {scrollCenter} from "../util/highlightById";
import {hasClosestByAttribute} from "../protyle/util/hasClosest";
import {setEditMode} from "../protyle/util/setEditMode";

View file

@ -5,7 +5,7 @@ import {Constants} from "../../constants";
import {focusByRange, getSelectionPosition} from "../../protyle/util/selection";
let renderKeyboardToolbarTimeout: number;
let showKeyboardToolbarUtil = false;
let showUtil = false;
const getSlashItem = (value: string, icon: string, text: string, focus = "false") => {
let iconHTML;
@ -145,18 +145,23 @@ const renderSlashMenu = (protyle: IProtyle, toolbarElement: Element) => {
protyle.hint.bindUploadEvent(protyle, utilElement);
};
const renderKeyboardToolbarUtil = () => {
const showKeyboardToolbarUtil = (oldScrollTop: number) => {
const toolbarElement = document.getElementById("keyboardToolbar");
const keyboardHeight = (parseInt(toolbarElement.getAttribute("data-keyboardheight")) + 42) + "px";
toolbarElement.style.height = keyboardHeight;
window.siyuan.mobile.editor.protyle.element.style.marginBottom = keyboardHeight;
window.siyuan.menus.menu.remove();
showKeyboardToolbarUtil = true;
showUtil = true;
setTimeout(() => {
showKeyboardToolbarUtil = false;
showUtil = false;
}, 1000);
};
const hideKeyboardToolbarUtil = () => {
document.getElementById("keyboardToolbar").style.height = "";
window.siyuan.mobile.editor.protyle.element.style.marginBottom = "42px";
};
const renderKeyboardToolbar = () => {
clearTimeout(renderKeyboardToolbarTimeout);
renderKeyboardToolbarTimeout = window.setTimeout(() => {
@ -230,11 +235,6 @@ const renderKeyboardToolbar = () => {
}, 620); // 需等待 range 更新
};
const hideKeyboardToolbarUtil = () => {
document.getElementById("keyboardToolbar").style.height = "";
window.siyuan.mobile.editor.protyle.element.style.marginBottom = "";
};
export const showKeyboardToolbar = (height: number) => {
if (getSelection().rangeCount === 0 || window.siyuan.config.editor.readOnly || window.siyuan.config.readonly) {
return;
@ -251,6 +251,7 @@ export const showKeyboardToolbar = (height: number) => {
!window.siyuan.mobile.editor.protyle.wysiwyg.element.contains(range.startContainer)) {
return;
}
window.siyuan.mobile.editor.protyle.element.style.marginBottom = "42px";
setTimeout(() => {
const contentElement = window.siyuan.mobile.editor.protyle.contentElement;
const cursorTop = getSelectionPosition(contentElement).top - contentElement.getBoundingClientRect().top;
@ -266,11 +267,13 @@ export const showKeyboardToolbar = (height: number) => {
};
export const hideKeyboardToolbar = () => {
if (showKeyboardToolbarUtil) {
if (showUtil) {
return;
}
const toolbarElement = document.getElementById("keyboardToolbar");
toolbarElement.classList.add("fn__none");
toolbarElement.style.height = "";
window.siyuan.mobile.editor.protyle.element.style.marginBottom = "";
};
export const activeBlur = () => {
@ -406,8 +409,9 @@ export const initKeyboardToolbar = () => {
focusByRange(range);
return;
} else if (type === "add") {
const oldScrollTop = window.siyuan.mobile.editor.protyle.contentElement.scrollTop;
renderSlashMenu(protyle, toolbarElement);
renderKeyboardToolbarUtil();
showKeyboardToolbarUtil(oldScrollTop);
return;
} else if (type === "more") {
protyle.breadcrumb.showMenu(protyle, {

View file

@ -29,7 +29,7 @@ export class Background {
this.element = document.createElement("div");
this.element.className = "protyle-background";
this.element.innerHTML = `<div class="protyle-background__img">
<img class="fn__none">
<img class="fn__none" style="isMobile()? "200px" : "30vh"">
<div class="protyle-icons">
<span class="protyle-icon protyle-icon--first b3-tooltips b3-tooltips__sw" style="position: relative" aria-label="${window.siyuan.languages.upload}"><input type="file" style="position: absolute;width: 22px;height: 100%;top: 0;left: 0;opacity: .001;overflow: hidden;cursor: pointer;"><svg><use xlink:href="#iconUpload"></use></svg></span>
<span class="protyle-icon b3-tooltips b3-tooltips__sw" data-type="link" aria-label="${window.siyuan.languages.link}"><svg><use xlink:href="#iconLink"></use></svg></span>
@ -389,7 +389,8 @@ export class Background {
}
if (img) {
this.element.style.minHeight = "30vh";
// 移动端键盘弹起和点击加号需保持滚动高度一致
this.element.style.minHeight = isMobile() ? "200px" : "30vh";
} else if (icon) {
this.element.style.minHeight = (this.tagsElement.clientHeight + 56) + "px";
} else if (tags) {