Vanessa 2024-01-01 01:21:30 +08:00
parent 4fcc7f1b4c
commit fe98812f74
7 changed files with 39 additions and 28 deletions

View file

@ -44,14 +44,14 @@ export class MobileBacklinks {
element: this.element.querySelector(".backlinkList") as HTMLElement,
data: null,
click(element: HTMLElement) {
openMobileFileById(app, element.getAttribute("data-node-id"), [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
openMobileFileById(app, element.getAttribute("data-node-id"), [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
}
});
this.mTree = new Tree({
element: this.element.querySelector(".backlinkMList") as HTMLElement,
data: null,
click: (element) => {
openMobileFileById(app, element.getAttribute("data-node-id"), [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
openMobileFileById(app, element.getAttribute("data-node-id"), [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
},
});
this.element.addEventListener("click", (event) => {

View file

@ -215,7 +215,7 @@ export class MobileFiles extends Model {
} else if (target.tagName === "LI") {
this.setCurrent(target);
if (target.getAttribute("data-type") === "navigation-file") {
openMobileFileById(app, target.getAttribute("data-node-id"));
openMobileFileById(app, target.getAttribute("data-node-id"), [Constants.CB_GET_SCROLL, Constants.CB_GET_HL]);
} else if (target.getAttribute("data-type") === "navigation-root") {
const ulElement = hasTopClosestByTag(target, "UL");
if (ulElement) {

View file

@ -35,7 +35,7 @@ export class MobileOutline {
document.getElementById(id)?.scrollIntoView();
} else {
checkFold(id, (zoomIn) => {
openMobileFileById(app, id, zoomIn ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML]);
openMobileFileById(app, id, zoomIn ? [Constants.CB_GET_HL, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML]);
});
}
}

View file

@ -13,6 +13,7 @@ import {pushBack} from "./util/MobileBackFoward";
import {setStorageVal} from "../protyle/util/compatibility";
import {showMessage} from "../dialog/message";
import {App} from "../index";
import {getDocByScroll, saveScroll} from "../protyle/scroll/saveScroll";
export const getCurrentEditor = () => {
return window.siyuan.mobile.popEditor || window.siyuan.mobile.editor;
@ -22,6 +23,7 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id};
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
if (window.siyuan.mobile.editor) {
saveScroll(window.siyuan.mobile.editor.protyle);
hideElements(["toolbar", "hint", "util"], window.siyuan.mobile.editor.protyle);
if (window.siyuan.mobile.editor.protyle.contentElement.classList.contains("fn__none")) {
setEditMode(window.siyuan.mobile.editor.protyle, "wysiwyg");
@ -46,32 +48,41 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_
showMessage(data.msg);
return;
}
const protyleOptions: IOptions = {
blockId: id,
rootId: data.data.rootID,
action,
render: {
scroll: true,
background: true,
gutter: true,
},
typewriterMode: true,
preview: {
actions: ["mp-wechat", "zhihu"]
}
}
if (window.siyuan.mobile.editor) {
pushBack();
addLoading(window.siyuan.mobile.editor.protyle);
fetchPost("/api/filetree/getDoc", {
id,
size: action.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
mode: action.includes(Constants.CB_GET_CONTEXT) ? 3 : 0,
}, getResponse => {
onGet({data: getResponse, protyle: window.siyuan.mobile.editor.protyle, action});
});
if (action.includes(Constants.CB_GET_SCROLL)) {
getDocByScroll({
protyle: window.siyuan.mobile.editor.protyle,
scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][data.data.rootID],
mergedOptions: protyleOptions
});
} else {
fetchPost("/api/filetree/getDoc", {
id,
size: action.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
mode: action.includes(Constants.CB_GET_CONTEXT) ? 3 : 0,
}, getResponse => {
onGet({data: getResponse, protyle: window.siyuan.mobile.editor.protyle, action});
});
}
window.siyuan.mobile.editor.protyle.undo.clear();
} else {
window.siyuan.mobile.editor = new Protyle(app, document.getElementById("editor"), {
blockId: id,
rootId: data.data.rootID,
action,
render: {
scroll: true,
background: true,
gutter: true,
},
typewriterMode: true,
preview: {
actions: ["mp-wechat", "zhihu"]
}
});
window.siyuan.mobile.editor = new Protyle(app, document.getElementById("editor"), protyleOptions);
}
(document.getElementById("toolbarName") as HTMLInputElement).value = data.data.rootTitle === "Untitled" ? "" : data.data.rootTitle;
setEditor();

View file

@ -152,7 +152,7 @@ window.hideKeyboardToolbar = hideKeyboardToolbar;
window.openFileByURL = (openURL) => {
if (openURL && isSYProtocol(openURL)) {
openMobileFileById(siyuanApp, getIdFromSYProtocol(openURL),
getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
return true;
}
return false;

View file

@ -170,7 +170,7 @@ export const initFramework = (app: App, isStart: boolean) => {
const idZoomIn = getIdZoomInByPath();
if (idZoomIn.id) {
openMobileFileById(app, idZoomIn.id,
idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
return;
}
if (window.siyuan.config.fileTree.closeTabsOnStart && isStart) {

View file

@ -25,7 +25,7 @@ export const onMessage = (app: App, data: IWebSocketData) => {
}
break;
case "openFileById":
openMobileFileById(app, data.data.id, [Constants.CB_GET_FOCUS]);
openMobileFileById(app, data.data.id, [Constants.CB_GET_HL]);
break;
case"txerr":
transactionError();