mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-12 10:14:21 +01:00
📱 输入键盘
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
830320096e
commit
621ca5d273
3 changed files with 26 additions and 45 deletions
|
|
@ -2,12 +2,7 @@ import {addScript, addScriptSync} from "../protyle/util/addScript";
|
|||
import {Constants} from "../constants";
|
||||
import {onMessage} from "./util/onMessage";
|
||||
import {genUUID} from "../util/genID";
|
||||
import {
|
||||
hasClosestBlock,
|
||||
hasClosestByAttribute,
|
||||
hasClosestByClassName,
|
||||
hasTopClosestByClassName
|
||||
} from "../protyle/util/hasClosest";
|
||||
import {hasClosestBlock, hasClosestByAttribute, hasTopClosestByClassName} from "../protyle/util/hasClosest";
|
||||
import {Model} from "../layout/Model";
|
||||
import "../assets/scss/mobile.scss";
|
||||
import {Menus} from "../menus";
|
||||
|
|
@ -37,7 +32,7 @@ import {correctHotkey} from "../boot/globalEvent/commonHotkey";
|
|||
import {processIOSPurchaseResponse} from "../util/iOSPurchase";
|
||||
import {updateControlAlt} from "../protyle/util/hotKey";
|
||||
import {nbsp2space} from "../protyle/util/normalizeText";
|
||||
import {callMobileAppShowKeyboard} from "./util/mobileAppUtil";
|
||||
import {callMobileAppShowKeyboard, canInput} from "./util/mobileAppUtil";
|
||||
|
||||
class App {
|
||||
public plugins: import("../plugin").Plugin[] = [];
|
||||
|
|
@ -102,16 +97,7 @@ class App {
|
|||
}, Constants.TIMEOUT_TRANSITION);
|
||||
}
|
||||
if (window.JSAndroid && window.JSAndroid.showKeyboard || window.JSHarmony && window.JSHarmony.showKeyboard) {
|
||||
const wysisygElement = hasClosestByClassName(event.target, "protyle-wysiwyg", true);
|
||||
let editElement: HTMLElement;
|
||||
if ((event.target.tagName === "TEXTAREA" ||
|
||||
(event.target.tagName === "INPUT" && ["email", "number", "password", "search", "tel", "text", "url", "", null].includes(event.target.getAttribute("type")))) &&
|
||||
event.target.getAttribute("readonly") !== "readonly") {
|
||||
editElement = event.target;
|
||||
} else if (wysisygElement && wysisygElement.getAttribute("data-readonly") === "false") {
|
||||
editElement = hasClosestByAttribute(event.target, "contenteditable", "true") as HTMLElement;
|
||||
}
|
||||
if (editElement) {
|
||||
if (canInput(event.target)) {
|
||||
callMobileAppShowKeyboard();
|
||||
}
|
||||
}
|
||||
|
|
@ -126,16 +112,8 @@ class App {
|
|||
} catch (e) {
|
||||
console.error("Error in focus event:", e);
|
||||
}
|
||||
const wysisygElement = hasClosestByClassName(this, "protyle-wysiwyg", true);
|
||||
if ((this.tagName === "TEXTAREA" ||
|
||||
(this.tagName === "INPUT" && ["email", "number", "password", "search", "tel", "text", "url", "", null].includes(this.getAttribute("type")))) &&
|
||||
this.getAttribute("readonly") !== "readonly") {
|
||||
if (canInput(this)) {
|
||||
callMobileAppShowKeyboard();
|
||||
} else if (wysisygElement && wysisygElement.getAttribute("data-readonly") === "false") {
|
||||
const editElement = hasClosestByAttribute(this, "contenteditable", "true") as HTMLElement;
|
||||
if (editElement) {
|
||||
callMobileAppShowKeyboard();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import {hideElements} from "../../protyle/ui/hideElements";
|
|||
import {softEnter} from "../../protyle/wysiwyg/enter";
|
||||
import {isInAndroid, isInEdge, isInHarmony} from "../../protyle/util/compatibility";
|
||||
import {tabCodeBlock} from "../../protyle/wysiwyg/codeBlock";
|
||||
import {callMobileAppShowKeyboard} from "./mobileAppUtil";
|
||||
import {callMobileAppShowKeyboard, canInput} from "./mobileAppUtil";
|
||||
|
||||
let renderKeyboardToolbarTimeout: number;
|
||||
let showUtil = false;
|
||||
|
|
@ -327,24 +327,7 @@ const hideKeyboardToolbarUtil = () => {
|
|||
const renderKeyboardToolbar = () => {
|
||||
clearTimeout(renderKeyboardToolbarTimeout);
|
||||
renderKeyboardToolbarTimeout = window.setTimeout(() => {
|
||||
if (getSelection().rangeCount === 0 ||
|
||||
window.siyuan.config.readonly ||
|
||||
document.getElementById("toolbarName").getAttribute("readonly") === "readonly" ||
|
||||
!document.activeElement || (
|
||||
document.activeElement &&
|
||||
!["INPUT", "TEXTAREA"].includes(document.activeElement.tagName) &&
|
||||
!document.activeElement.classList.contains("protyle-wysiwyg") &&
|
||||
document.activeElement.getAttribute("contenteditable") !== "true"
|
||||
)) {
|
||||
hideKeyboardToolbar();
|
||||
return;
|
||||
}
|
||||
// 编辑器设置界面点击空白或关闭,焦点不知何故会飘移到编辑器上
|
||||
if (document.activeElement &&
|
||||
!["INPUT", "TEXTAREA"].includes(document.activeElement.tagName) && (
|
||||
document.getElementById("menu").style.transform === "translateX(0px)" ||
|
||||
document.getElementById("model").style.transform === "translateY(0px)"
|
||||
)) {
|
||||
if (!canInput(document.activeElement)) {
|
||||
hideKeyboardToolbar();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import {hasClosestByAttribute, hasClosestByClassName} from "../../protyle/util/hasClosest";
|
||||
|
||||
export const callMobileAppShowKeyboard = () => {
|
||||
if (window.JSAndroid && window.JSAndroid.showKeyboard) {
|
||||
window.JSAndroid.showKeyboard();
|
||||
|
|
@ -5,3 +7,21 @@ export const callMobileAppShowKeyboard = () => {
|
|||
window.JSHarmony.showKeyboard();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const canInput = (element: Element) => {
|
||||
if (!element || element.nodeType !== 1) {
|
||||
return false;
|
||||
}
|
||||
if ((
|
||||
element.tagName === "TEXTAREA" ||
|
||||
(element.tagName === "INPUT" && ["email", "number", "password", "search", "tel", "text", "url", "", null].includes(element.getAttribute("type")))
|
||||
) && element.getAttribute("readonly") !== "readonly") {
|
||||
return element
|
||||
}
|
||||
const wysisygElement = hasClosestByClassName(element, "protyle-wysiwyg", true);
|
||||
if (wysisygElement && wysisygElement.getAttribute("data-readonly") === "false") {
|
||||
return hasClosestByAttribute(element, "contenteditable", "true")
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue