Vanessa 2022-06-29 20:25:30 +08:00
parent b0377a168b
commit dab5377a4b
7 changed files with 50 additions and 20 deletions

View file

@ -3,11 +3,11 @@ import {fetchPost} from "../util/fetch";
/// #if !MOBILE
import {getAllModels} from "../layout/getAll";
import {ipcRenderer} from "electron";
import {exportLayout} from "../layout/util";
/// #endif
import {showMessage} from "./message";
import {Dialog} from "./index";
import {isMobile} from "../util/functions";
import {exportLayout} from "../layout/util";
export const lockFile = (id: string) => {
const html = `<div class="b3-dialog__scrim"></div>
@ -134,9 +134,13 @@ export const transactionError = (data: { code: number, data: string }) => {
});
const btnsElement = dialog.element.querySelectorAll(".b3-button");
btnsElement[0].addEventListener("click", () => {
/// #if MOBILE
exitSiYuan();
/// #else
exportLayout(false, () => {
exitSiYuan();
});
/// #endif
});
btnsElement[1].addEventListener("click", () => {
fetchPost("/api/filetree/refreshFiletree", {});

View file

@ -25,8 +25,9 @@ import {addEmoji, filterEmoji, lazyLoadEmoji, unicode2Emoji} from "../../emoji";
import {escapeHtml} from "../../util/escape";
import {blockRender} from "../markdown/blockRender";
import {uploadFiles} from "../upload";
/// #if !MOBILE
import {openFileById} from "../../editor/util";
import {isMobile} from "../../util/functions";
/// #endif
import {openMobileFileById} from "../../mobile/editor";
import {getIconByType} from "../../editor/getIcon";
@ -497,15 +498,15 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
md: ""
}, () => {
insertHTML(genEmptyBlock(false, false, `<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">Untitled</span>`), protyle);
if (isMobile()) {
/// #if MOBILE
openMobileFileById(newSubDocId, true);
} else {
/// #else
openFileById({
id: newSubDocId,
hasContext: true,
action: [Constants.CB_GET_HL]
});
}
/// #endif
});
return;
} else if (Constants.INLINE_TYPE.includes(value)) {

View file

@ -10,12 +10,14 @@ import {getSearch, isMobile} from "../../util/functions";
/// #if !BROWSER
import {shell} from "electron";
/// #endif
/// #if !MOBILE
import {openAsset, openBy} from "../../editor/util";
/// #endif
import {fetchPost} from "../../util/fetch";
import {processRender} from "../util/processCode";
import {highlightRender} from "../markdown/highlightRender";
import {speechRender} from "../markdown/speechRender";
import {mediaRender} from "../markdown/mediaRender";
import {openAsset, openBy} from "../../editor/util";
export class Preview {
public element: HTMLElement;
@ -46,6 +48,7 @@ export class Preview {
event.stopPropagation();
event.preventDefault();
if (isLocalPath(linkAddress)) {
/// #if !MOBILE
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname((linkAddress.split("?page")[0])))) {
openAsset(linkAddress.split("?page")[0], parseInt(getSearch("page", linkAddress)));
} else {
@ -53,6 +56,7 @@ export class Preview {
openBy(linkAddress, "folder");
/// #endif
}
/// #endif
} else {
/// #if !BROWSER
shell.openExternal(linkAddress).catch((e) => {

View file

@ -8,7 +8,9 @@ import {processRender} from "./processCode";
import {highlightRender} from "../markdown/highlightRender";
import {blockRender} from "../markdown/blockRender";
import {highlightById} from "../../util/highlightById";
/// #if !MOBILE
import {pushBack} from "../../util/backForward";
/// #endif
import {focusBlock} from "./selection";
import {hasClosestByAttribute, hasClosestByClassName} from "./hasClosest";
import {preventScroll} from "../scroll/preventScroll";
@ -144,9 +146,11 @@ const setHTML = (options: { content: string, action?: string[] }, protyle: IProt
if (options.action.includes(Constants.CB_GET_HL)) {
preventScroll(protyle); // 搜索页签滚动会导致再次请求
const hlElement = highlightById(protyle, protyle.block.id, true);
/// #if !MOBILE
if (hlElement && !options.action.includes(Constants.CB_GET_UNUNDO)) {
pushBack(protyle, undefined, hlElement);
}
/// #endif
} else if (options.action.includes(Constants.CB_GET_FOCUS)) {
let focusElement: Element;
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${protyle.block.id}"]`)).find((item: HTMLElement) => {
@ -161,9 +165,11 @@ const setHTML = (options: { content: string, action?: string[] }, protyle: IProt
}
if (focusElement && !protyle.wysiwyg.element.firstElementChild.isSameNode(focusElement)) {
focusBlock(focusElement);
/// #if !MOBILE
if (!options.action.includes(Constants.CB_GET_UNUNDO)) {
pushBack(protyle, undefined, focusElement);
}
/// #endif
focusElement.scrollIntoView();
// 减少抖动 https://ld246.com/article/1654263598088
setTimeout(() => {
@ -171,16 +177,20 @@ const setHTML = (options: { content: string, action?: string[] }, protyle: IProt
}, Constants.TIMEOUT_BLOCKLOAD);
} else {
focusBlock(protyle.wysiwyg.element.firstElementChild);
/// #if !MOBILE
if (!options.action.includes(Constants.CB_GET_UNUNDO)) {
pushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild);
}
/// #endif
}
} else if (options.action.includes(Constants.CB_GET_FOCUSFIRST)) {
// settimeout 时间需短一点,否则定位后快速滚动无效
preventScroll(protyle, 8, 256);
protyle.contentElement.scrollTop = 8;
focusBlock(protyle.wysiwyg.element.firstElementChild);
/// #if !MOBILE
pushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild);
/// #endif
}
if (protyle.disabled) {
disabledProtyle(protyle);

View file

@ -42,12 +42,12 @@ import {keydown} from "./keydown";
import {openMobileFileById} from "../../mobile/editor";
import {removeBlock} from "./remove";
import {highlightRender} from "../markdown/highlightRender";
import {getAllModels} from "../../layout/getAll";
import {setPosition} from "../../util/setPosition";
import {openAttr} from "../../menus/commonMenuItem";
import {blockRender} from "../markdown/blockRender";
import {pushBack} from "../../util/backForward";
/// #if !MOBILE
import {getAllModels} from "../../layout/getAll";
import {pushBack} from "../../util/backForward";
import {openAsset, openBy, openFileById} from "../../editor/util";
/// #endif
import {BlockPanel} from "../../block/Panel";
@ -157,6 +157,7 @@ export class WYSIWYG {
}
nodeElement = tempElement;
}
/// #if !MOBILE
if (protyle.model) {
getAllModels().outline.forEach(item => {
if (item.blockId === protyle.block.rootID) {
@ -173,6 +174,7 @@ export class WYSIWYG {
}
});
}
/// #endif
}
private bindEvent(protyle: IProtyle) {
@ -1381,6 +1383,7 @@ export class WYSIWYG {
}
/// #endif
});
/// #if !MOBILE
if (protyle.model) {
// 打开双链需记录到后退中 https://github.com/siyuan-note/insider/issues/801
let blockElement: HTMLElement | false;
@ -1393,6 +1396,7 @@ export class WYSIWYG {
pushBack(protyle, getEditorRange(this.element), blockElement);
}
}
/// #endif
return;
}
@ -1726,7 +1730,9 @@ export class WYSIWYG {
if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select")) {
countSelectWord(newRange);
}
/// #if !MOBILE
pushBack(protyle, newRange);
/// #endif
}, isMobile() ? 520 : 0); // Android 双击慢了出不来
protyle.toolbar.isNewEmptyInline = false;

View file

@ -10,7 +10,9 @@ import {lockFile} from "../../dialog/processSystem";
import {setFold} from "../../menus/protyle";
import {addLoading} from "../ui/initUI";
import {onGet} from "../util/onGet";
/// #if !MOBILE
import {getAllModels} from "../../layout/getAll";
/// #endif
import {removeFoldHeading} from "../util/heading";
import {genEmptyElement, genSBElement} from "../../block/util";
import {hideElements} from "../ui/hideElements";
@ -311,6 +313,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
endOffset: range.endOffset,
};
}
/// #if !MOBILE
if (!updateElement) {
// 打开两个相同的文档 A、A1从 A 拖拽块 B 到 A1在后续 ws 处理中,无法获取到拖拽出去的 B
getAllModels().editor.forEach(editor => {
@ -320,6 +323,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
}
});
}
/// #endif
if (operation.previousID) {
let beforeElement: Element;
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`)).find(item => {

View file

@ -1,6 +1,7 @@
import {hideMessage, showMessage} from "../dialog/message";
/// #if !MOBILE
import {exportLayout} from "../layout/util";
import {isMobile} from "./functions";
/// #endif
export const processMessage = (response: IWebSocketData) => {
if ("msg" === response.cmd) {
@ -19,11 +20,11 @@ export const processMessage = (response: IWebSocketData) => {
return false;
}
if ("reloadui" === response.cmd) {
if (isMobile()) {
/// #if MOBILE
window.location.reload();
} else {
/// #else
exportLayout(true);
}
/// #endif
return false;
}