diff --git a/app/src/assets/scss/mobile.scss b/app/src/assets/scss/mobile.scss index 89f432ca3..8ca3f0382 100644 --- a/app/src/assets/scss/mobile.scss +++ b/app/src/assets/scss/mobile.scss @@ -245,6 +245,11 @@ border-bottom: 1px solid var(--b3-theme-surface-lighter); } + &__util { + flex: 1; + overflow: auto; + } + &__split { width: 1px; height: 28px; @@ -253,26 +258,25 @@ flex-shrink: 0; } - &__util { - flex: 1; - overflow: auto; - } - - button { + &__action { background: transparent; padding: 0; border: 0; + color: var(--b3-theme-on-surface); &[disabled] { opacity: 0.38; } + &.protyle-toolbar__item--current { + color: var(--b3-theme-primary); + } + svg { height: 16px; width: 16px; float: left; padding: 12px; - color: var(--b3-theme-on-surface); &.keyboard__svg--big { width: 30px; diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts index 869d45258..0ac5f9334 100644 --- a/app/src/mobile/util/keyboardToolbar.ts +++ b/app/src/mobile/util/keyboardToolbar.ts @@ -45,11 +45,11 @@ const renderKeyboardToolbar = () => { const range = getSelection().getRangeAt(0); const selectText = range.toString(); const isProtyle = hasClosestByClassName(range.startContainer, "protyle-wysiwyg", true); + const protyle = window.siyuan.mobile.editor.protyle; 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 { @@ -75,6 +75,20 @@ const renderKeyboardToolbar = () => { } } if (selectText && isProtyle) { + dynamicElements[1].querySelectorAll('.protyle-toolbar__item--current').forEach(item => { + item.classList.remove("protyle-toolbar__item--current"); + }); + const types = protyle.toolbar.getCurrentType(); + types.forEach(item => { + if (["search-mark", "a", "block-ref", "virtual-block-ref", "text", "file-annotation-ref", "inline-math", + "inline-memo", "", "backslash"].includes(item)) { + return; + } + const itemElement = dynamicElements[1].querySelector(`[data-type="${item}"]`); + if (itemElement) { + itemElement.classList.add("protyle-toolbar__item--current"); + } + }); dynamicElements[1].classList.remove("fn__none"); } else { dynamicElements[1].classList.add("fn__none"); @@ -138,44 +152,44 @@ export const initKeyboardToolbar = () => { toolbarElement.innerHTML = `
`; toolbarElement.addEventListener("click", (event) => { diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index e512e028c..ebb49705b 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -315,7 +315,8 @@ export class Toolbar { item.replaceWith(spanElement); }); } - const actionBtn = action === "toolbar" ? this.element.querySelector(`[data-type="${type}"]`) : undefined; + const toolbarElement = isMobile() ? document.querySelector("#keyboardToolbar .keyboard__dynamic") : this.element + const actionBtn = action === "toolbar" ? toolbarElement.querySelector(`[data-type="${type}"]`) : undefined; const newNodes: Node[] = []; if (type === "clear" || actionBtn?.classList.contains("protyle-toolbar__item--current") || ( @@ -323,7 +324,7 @@ export class Toolbar { )) { // 移除 if (type === "clear") { - this.element.querySelectorAll('[data-type="em"],[data-type="u"],[data-type="s"],[data-type="mark"],[data-type="sup"],[data-type="sub"],[data-type="strong"]').forEach(item => { + toolbarElement.querySelectorAll('[data-type="em"],[data-type="u"],[data-type="s"],[data-type="mark"],[data-type="sup"],[data-type="sub"],[data-type="strong"]').forEach(item => { item.classList.remove("protyle-toolbar__item--current"); }); } else if (actionBtn) { @@ -414,8 +415,8 @@ export class Toolbar { }); } else { // 添加 - if (!this.element.classList.contains("fn__none") && type !== "text") { - this.element.querySelector(`[data-type="${type}"]`).classList.add("protyle-toolbar__item--current"); + if (!this.element.classList.contains("fn__none") && type !== "text" && actionBtn) { + actionBtn.classList.add("protyle-toolbar__item--current"); } if (selectText === "") { const inlineElement = document.createElement("span"); @@ -479,9 +480,7 @@ export class Toolbar { types.find((item, index) => { if (item === "sup") { types.splice(index, 1); - if (!this.element.classList.contains("fn__none")) { - this.element.querySelector('[data-type="sup"]').classList.remove("protyle-toolbar__item--current"); - } + toolbarElement.querySelector('[data-type="sup"]').classList.remove("protyle-toolbar__item--current"); return true; } }); @@ -489,9 +488,7 @@ export class Toolbar { types.find((item, index) => { if (item === "sub") { types.splice(index, 1); - if (!this.element.classList.contains("fn__none")) { - this.element.querySelector('[data-type="sub"]').classList.remove("protyle-toolbar__item--current"); - } + toolbarElement.querySelector('[data-type="sub"]').classList.remove("protyle-toolbar__item--current"); return true; } });