This commit is contained in:
Vanessa 2022-10-08 14:31:34 +08:00
parent a1f7b11625
commit e793431202
3 changed files with 24 additions and 14 deletions

View file

@ -16,7 +16,7 @@ import {hasTopClosestByTag} from "../../protyle/util/hasClosest";
import {MobileBacklinks} from "./MobileBacklinks";
import {MobileBookmarks} from "./MobileBookmarks";
import {MobileTags} from "./MobileTags";
import {initKeyboardToolbar} from "./showKeyboardToolbar";
import {hideKeyboardToolbar, initKeyboardToolbar} from "./showKeyboardToolbar";
export const initFramework = () => {
setInlineStyle();
@ -70,7 +70,7 @@ export const initFramework = () => {
});
});
new MobileFiles();
document.getElementById("toolbarFile").addEventListener(getEventName(), () => {
document.getElementById("toolbarFile").addEventListener("click", () => {
sidebarElement.style.left = "0";
document.querySelector(".scrim").classList.remove("fn__none");
const type = sidebarElement.querySelector(".toolbar--border .toolbar__icon--active").getAttribute("data-type");
@ -84,7 +84,8 @@ export const initFramework = () => {
tag.update();
}
});
document.getElementById("toolbarMore").addEventListener(getEventName(), () => {
// 用 touchstart 会导致键盘不收起
document.getElementById("toolbarMore").addEventListener("click", () => {
popMenu();
});
const editElement = document.getElementById("toolbarEdit");
@ -138,6 +139,9 @@ export const initFramework = () => {
const initEditorName = () => {
const inputElement = document.getElementById("toolbarName") as HTMLInputElement;
inputElement.setAttribute("placeholder", window.siyuan.languages._kernel[16]);
inputElement.addEventListener("focus", () => {
hideKeyboardToolbar();
});
inputElement.addEventListener("blur", () => {
if (window.siyuan.config.readonly || document.querySelector("#toolbarEdit use").getAttribute("xlink:href") === "#iconEdit") {
return;

View file

@ -7,18 +7,21 @@ import {focusByRange} from "../../protyle/util/selection";
import {scrollCenter} from "../../util/highlightById";
export const showKeyboardToolbar = (bottom = 0) => {
const toolbarElement = document.getElementById("keyboardToolbar");
toolbarElement.classList.remove("fn__none");
toolbarElement.style.bottom = bottom + "px";
let range: Range;
if (getSelection().rangeCount > 0) {
range = getSelection().getRangeAt(0);
}
if (!range || !window.siyuan.mobileEditor ||
!window.siyuan.mobileEditor.protyle.wysiwyg.element.contains(range.startContainer)) {
const range = getSelection().getRangeAt(0);
if (!window.siyuan.mobileEditor ||
!window.siyuan.mobileEditor.protyle.wysiwyg.element.contains(range.startContainer)) {
return;
}
} else {
return;
}
const toolbarElement = document.getElementById("keyboardToolbar");
if (!toolbarElement.classList.contains("fn__none")) {
return;
}
toolbarElement.classList.remove("fn__none");
toolbarElement.style.bottom = bottom + "px";
if ("android" === window.siyuan.config.system.container && window.JSAndroid) {
// Android 端事件需要滞后一些,所以这里延迟一下
setTimeout(() => {

View file

@ -26,6 +26,7 @@ import {getDisplayName} from "../util/pathName";
import {onGet} from "./util/onGet";
import {reloadProtyle} from "./util/reload";
import {renderBacklink} from "./wysiwyg/renderBacklink";
import {showKeyboardToolbar} from "../mobile/util/showKeyboardToolbar";
export class Protyle {
@ -179,8 +180,8 @@ export class Protyle {
// 需等待 getDoc 完成后再执行,否则在无页签的时候 updatePanelByEditor 会执行2次
// 只能用 focusin否则点击表格无法执行
/// #if !MOBILE
this.protyle.wysiwyg.element.addEventListener("focusin", () => {
/// #if !MOBILE
if (this.protyle && this.protyle.model) {
let needUpdate = true;
if (this.protyle.model.element.parentElement.parentElement.classList.contains("layout__wnd--active") && this.protyle.model.headElement.classList.contains("item--focus")) {
@ -200,8 +201,10 @@ export class Protyle {
item.classList.remove("layout__wnd--active");
});
}
/// #else
showKeyboardToolbar();
/// #endif
});
/// #endif
// 需等渲染完后再回调,用于定位搜索字段 https://github.com/siyuan-note/siyuan/issues/3171
if (mergedOptions.after) {
mergedOptions.after(this);