+ const isProtyle = hasClosestByClassName(range.startContainer, "protyle-wysiwyg", true)
+ if (selectText || !isProtyle) {
+ dynamicElements[0].classList.add("fn__none")
+ } else {
+ dynamicElements[0].classList.remove("fn__none")
+ const protyle = window.siyuan.mobile.editor.protyle;
+ if (protyle.undo.undoStack.length === 0) {
+ dynamicElements[0].querySelector('[data-type="undo"]').setAttribute("disabled", "disabled");
+ } else {
+ dynamicElements[0].querySelector('[data-type="undo"]').removeAttribute("disabled");
+ }
+ if (protyle.undo.redoStack.length === 0) {
+ dynamicElements[0].querySelector('[data-type="redo"]').setAttribute("disabled", "disabled");
+ } else {
+ dynamicElements[0].querySelector('[data-type="redo"]').removeAttribute("disabled");
+ }
+ }
+ if (selectText && isProtyle) {
+ dynamicElements[1].classList.remove("fn__none")
+ } else {
+ dynamicElements[1].classList.add("fn__none")
+ }
+ }, 620); // 需等待 range 更新
+};
+
+export const hideKeyboardToolbar = () => {
+ const toolbarElement = document.getElementById("keyboardToolbar");
+ toolbarElement.classList.add("fn__none");
+};
+
+export const hideKeyboard = () => {
+ (document.activeElement as HTMLElement).blur();
+};
+
+export const initKeyboardToolbar = () => {
+ document.addEventListener("selectionchange", () => {
+ renderKeyboardToolbar()
+ }, false);
+
+ const toolbarElement = document.getElementById("keyboardToolbar");
+ toolbarElement.innerHTML = `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -89,24 +125,6 @@ export const renderKeyboardToolbar = () => {
`;
- }, 620) // 需等待 range 更新
-};
-
-export const hideKeyboardToolbar = () => {
- const toolbarElement = document.getElementById("keyboardToolbar");
- toolbarElement.classList.add("fn__none");
-};
-
-export const hideKeyboard = () => {
- (document.activeElement as HTMLElement).blur();
-};
-
-export const initKeyboardToolbar = () => {
- document.addEventListener("selectionchange", () => {
- renderKeyboardToolbar()
- }, false);
-
- const toolbarElement = document.getElementById("keyboardToolbar");
toolbarElement.addEventListener("click", (event) => {
const target = event.target as HTMLElement;
const buttonElement = hasClosestByMatchTag(target, "BUTTON");
@@ -155,12 +173,12 @@ export const initKeyboardToolbar = () => {
}
// inline element
if (["a", "block-ref", "inline-math", "inline-memo", "text"].includes(type)) {
- protyle.toolbar.element.querySelector(`[data-type="${type}"]`).dispatchEvent(new CustomEvent("block-ref" === type ? getEventName() : "click"));
+ protyle.toolbar.element.querySelector(`[data-type="${type}"]`).dispatchEvent(new CustomEvent("text" === type ? getEventName() : "click"));
return true;
}
if (["strong", "em", "s", "code", "mark", "tag", "u", "sup", "clear", "sub", "kbd"].includes(type)) {
protyle.toolbar.setInlineMark(protyle, type, "toolbar");
- return ;
+ return;
}
// TODO block element
if (type === "up") {