This commit is contained in:
Vanessa 2023-03-03 23:57:51 +08:00
parent 1b5a049e1a
commit 1a0f176a05
3 changed files with 16 additions and 16 deletions

View file

@ -38,7 +38,7 @@ export const showKeyboardToolbar = (bottom = 0) => {
let renderKeyboardToolbarTimeout: number; let renderKeyboardToolbarTimeout: number;
export const renderKeyboardToolbar = () => { export const renderKeyboardToolbar = () => {
clearTimeout(renderKeyboardToolbarTimeout) clearTimeout(renderKeyboardToolbarTimeout);
renderKeyboardToolbarTimeout = window.setTimeout(() => { renderKeyboardToolbarTimeout = window.setTimeout(() => {
if (getSelection().rangeCount === 0 || window.siyuan.config.editor.readOnly || window.siyuan.config.readonly) { if (getSelection().rangeCount === 0 || window.siyuan.config.editor.readOnly || window.siyuan.config.readonly) {
return; return;
@ -46,11 +46,11 @@ export const renderKeyboardToolbar = () => {
const dynamicElements = document.querySelectorAll("#keyboardToolbar .keyboard__dynamic"); const dynamicElements = document.querySelectorAll("#keyboardToolbar .keyboard__dynamic");
const range = getSelection().getRangeAt(0); const range = getSelection().getRangeAt(0);
const selectText = range.toString(); const selectText = range.toString();
const isProtyle = hasClosestByClassName(range.startContainer, "protyle-wysiwyg", true) const isProtyle = hasClosestByClassName(range.startContainer, "protyle-wysiwyg", true);
if (selectText || !isProtyle) { if (selectText || !isProtyle) {
dynamicElements[0].classList.add("fn__none") dynamicElements[0].classList.add("fn__none");
} else { } else {
dynamicElements[0].classList.remove("fn__none") dynamicElements[0].classList.remove("fn__none");
const protyle = window.siyuan.mobile.editor.protyle; const protyle = window.siyuan.mobile.editor.protyle;
if (protyle.undo.undoStack.length === 0) { if (protyle.undo.undoStack.length === 0) {
dynamicElements[0].querySelector('[data-type="undo"]').setAttribute("disabled", "disabled"); dynamicElements[0].querySelector('[data-type="undo"]').setAttribute("disabled", "disabled");
@ -64,9 +64,9 @@ export const renderKeyboardToolbar = () => {
} }
} }
if (selectText && isProtyle) { if (selectText && isProtyle) {
dynamicElements[1].classList.remove("fn__none") dynamicElements[1].classList.remove("fn__none");
} else { } else {
dynamicElements[1].classList.add("fn__none") dynamicElements[1].classList.add("fn__none");
} }
}, 620); // 需等待 range 更新 }, 620); // 需等待 range 更新
}; };
@ -82,7 +82,7 @@ export const hideKeyboard = () => {
export const initKeyboardToolbar = () => { export const initKeyboardToolbar = () => {
document.addEventListener("selectionchange", () => { document.addEventListener("selectionchange", () => {
renderKeyboardToolbar() renderKeyboardToolbar();
}, false); }, false);
const toolbarElement = document.getElementById("keyboardToolbar"); const toolbarElement = document.getElementById("keyboardToolbar");
@ -151,15 +151,15 @@ export const initKeyboardToolbar = () => {
return; return;
} }
if (type === "goback") { if (type === "goback") {
const dynamicElements = document.querySelectorAll("#keyboardToolbar .keyboard__dynamic") const dynamicElements = document.querySelectorAll("#keyboardToolbar .keyboard__dynamic");
dynamicElements[0].classList.remove("fn__none") dynamicElements[0].classList.remove("fn__none");
dynamicElements[1].classList.add("fn__none") dynamicElements[1].classList.add("fn__none");
return; return;
} }
if (type === "goinline") { if (type === "goinline") {
const dynamicElements = document.querySelectorAll("#keyboardToolbar .keyboard__dynamic") const dynamicElements = document.querySelectorAll("#keyboardToolbar .keyboard__dynamic");
dynamicElements[1].classList.remove("fn__none") dynamicElements[1].classList.remove("fn__none");
dynamicElements[0].classList.add("fn__none") dynamicElements[0].classList.add("fn__none");
return; return;
} }

View file

@ -553,7 +553,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button> <button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
</div>`, </div>`,
width: isMobile() ? "80vw" : "520px", width: isMobile() ? "80vw" : "520px",
}) });
const inputElement = dialog.element.querySelector("input") as HTMLInputElement; const inputElement = dialog.element.querySelector("input") as HTMLInputElement;
const btnsElement = dialog.element.querySelectorAll(".b3-button"); const btnsElement = dialog.element.querySelectorAll(".b3-button");
dialog.bindInput(inputElement, () => { dialog.bindInput(inputElement, () => {

View file

@ -54,8 +54,8 @@ const focusStack = async (stack: IBackStack) => {
callback(tab) { callback(tab) {
const scrollAttr = saveScroll(stack.protyle, true); const scrollAttr = saveScroll(stack.protyle, true);
scrollAttr.focusId = stack.id; scrollAttr.focusId = stack.id;
scrollAttr.focusStart = stack.position.start scrollAttr.focusStart = stack.position.start;
scrollAttr.focusEnd = stack.position.end scrollAttr.focusEnd = stack.position.end;
const editor = new Editor({ const editor = new Editor({
tab, tab,
scrollAttr, scrollAttr,