This commit is contained in:
Vanessa 2022-06-30 15:56:44 +08:00
parent 3b29cc7bfc
commit 922e86bc8b
8 changed files with 101 additions and 75 deletions

View file

@ -1,5 +1,6 @@
/// #if !MOBILE
import {getAllModels} from "../../layout/getAll";
import {isMobile} from "../../util/functions";
/// #endif
import {setPadding} from "../ui/initUI";
export const fullscreen = (element: Element, btnElement?: Element) => {
@ -22,7 +23,8 @@ export const fullscreen = (element: Element, btnElement?: Element) => {
} else {
btnElement.querySelector("use").setAttribute("xlink:href", "#iconContract");
}
} else if (!isMobile()) {
}
/// #if !MOBILE
window.siyuan.editorIsFullscreen = !isFullscreen;
getAllModels().editor.forEach(item => {
if (window.siyuan.editorIsFullscreen) {
@ -35,5 +37,5 @@ export const fullscreen = (element: Element, btnElement?: Element) => {
setPadding(item.editor.protyle);
}
});
}
/// #endif
};

View file

@ -14,12 +14,14 @@ import {isMobile} from "../../util/functions";
import {zoomOut} from "../../menus/protyle";
import {getEditorRange} from "../util/selection";
import {setPadding} from "../ui/initUI";
import {onGet} from "../util/onGet";
/// #if !MOBILE
import {openFileById} from "../../editor/util";
import {getAllModels} from "../../layout/getAll";
/// #endif
/// #if !BROWSER
import {getCurrentWindow} from "@electron/remote";
/// #endif
import {openFileById} from "../../editor/util";
import {getAllModels} from "../../layout/getAll";
import {onGet} from "../util/onGet";
export class Breadcrumb {
public element: HTMLElement;
@ -44,9 +46,9 @@ export class Breadcrumb {
const id = target.getAttribute("data-node-id");
if (id) {
if (protyle.options.render.breadcrumbDocName && window.siyuan.ctrlIsPressed) {
if (!isMobile()) {
/// #if !MOBILE
openFileById({id, action: [Constants.CB_GET_FOCUS]});
}
/// #endif
} else {
zoomOut(protyle, id);
}
@ -218,7 +220,7 @@ export class Breadcrumb {
fetchPost("/api/format/autoSpace", {
id: protyle.block.rootID
}, () => {
if (isMobile()) {
/// #if MOBILE
fetchPost("/api/filetree/getDoc", {
id: protyle.block.id,
mode: 0,
@ -226,7 +228,7 @@ export class Breadcrumb {
}, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_FOCUS]);
});
} else {
/// #else
getAllModels().editor.forEach(item => {
if (item.editor.protyle.block.rootID === protyle.block.rootID) {
fetchPost("/api/filetree/getDoc", {
@ -238,7 +240,7 @@ export class Breadcrumb {
});
}
});
}
/// #endif
});
}
}).element);
@ -248,7 +250,7 @@ export class Breadcrumb {
fetchPost("/api/format/netImg2LocalAssets", {
id: protyle.block.rootID
}, () => {
if (isMobile()) {
/// #if MOBILE
fetchPost("/api/filetree/getDoc", {
id: protyle.block.id,
mode: 0,
@ -256,7 +258,7 @@ export class Breadcrumb {
}, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_FOCUS]);
});
} else {
/// #else
getAllModels().editor.forEach(item => {
if (item.editor.protyle.block.rootID === protyle.block.rootID) {
fetchPost("/api/filetree/getDoc", {
@ -268,7 +270,7 @@ export class Breadcrumb {
});
}
});
}
/// #endif
});
}
}).element);

View file

@ -6,7 +6,9 @@ import {fetchPost} from "../../util/fetch";
import {getRandomEmoji, openEmojiPanel, unicode2Emoji, updateFileTreeEmoji, updateOutlineEmoji} from "../../emoji";
import {upDownHint} from "../../util/upDownHint";
import {setPosition} from "../../util/setPosition";
/// #if !MOBILE
import {openGlobalSearch} from "../../search/util";
/// #endif
import {getEventName} from "../util/compatibility";
import {Dialog} from "../../dialog";
@ -278,9 +280,9 @@ export class Background {
event.stopPropagation();
break;
} else if (type === "open-search") {
if (!isMobile()) {
/// #if !MOBILE
openGlobalSearch(`#${target.textContent}#`, !window.siyuan.ctrlIsPressed);
}
/// #endif
event.preventDefault();
event.stopPropagation();
break;

View file

@ -16,16 +16,16 @@ import {Constants} from "../../constants";
import {hasClosestByClassName} from "../util/hasClosest";
import {matchHotKey} from "../util/hotKey";
import {updateHotkeyTip, writeText} from "../util/compatibility";
import {setPanelFocus} from "../../layout/util";
import {escapeHtml} from "../../util/escape";
import {updatePanelByEditor} from "../../editor/util";
import * as dayjs from "dayjs";
import {setPanelFocus} from "../../layout/util";
import {updatePanelByEditor} from "../../editor/util";
import {openBacklink, openGraph, openOutline} from "../../layout/dock/util";
import {setTitle} from "../../dialog/processSystem";
import {getNoContainerElement} from "../wysiwyg/getBlock";
import {commonHotkey} from "../wysiwyg/commonHotkey";
import {setPosition} from "../../util/setPosition";
import {code160to32} from "../util/code160to32";
import {openBacklink, openGraph, openOutline} from "../../layout/dock/util";
import {deleteFile} from "../../editor/deleteFile";
export class Title {

View file

@ -16,7 +16,9 @@ import {Gutter} from "./gutter";
import {Breadcrumb} from "./breadcrumb";
import {onTransaction} from "./wysiwyg/transaction";
import {fetchPost} from "../util/fetch";
/// #if !MOBILE
import {Title} from "./header/Title";
/// #endif
import {Background} from "./header/Background";
import {getDisplayName} from "../util/pathName";
import {onGet} from "./util/onGet";
@ -49,9 +51,11 @@ class Protyle {
this.protyle.hint = new Hint(this.protyle);
this.protyle.breadcrumb = new Breadcrumb(this.protyle);
/// #if !MOBILE
if (mergedOptions.render.title) {
this.protyle.title = new Title(this.protyle);
}
/// #endif
if (mergedOptions.render.background) {
this.protyle.background = new Background(this.protyle);
}

View file

@ -10,14 +10,16 @@ import {hideElements} from "../ui/hideElements";
import {mathRender} from "../markdown/mathRender";
import {fetchPost, fetchSyncPost} from "../../util/fetch";
import {onGet} from "./onGet";
/// #if !MOBILE
import {getInstanceById} from "../../layout/util";
import {Editor} from "../../editor";
import {Tab} from "../../layout/Tab";
import {blockRender} from "../markdown/blockRender";
import {getAllModels} from "../../layout/getAll";
import {updatePanelByEditor} from "../../editor/util";
/// #endif
import {Editor} from "../../editor";
import {blockRender} from "../markdown/blockRender";
import {processRender} from "./processCode";
import {highlightRender} from "../markdown/highlightRender";
import {updatePanelByEditor} from "../../editor/util";
const dragSb = (protyle: IProtyle, sourceElements: Element[], targetElement: Element, isBottom: boolean, direct: "col" | "row") => {
const isSameDoc = protyle.element.contains(sourceElements[0]);
@ -211,6 +213,7 @@ const dragSb = (protyle: IProtyle, sourceElements: Element[], targetElement: Ele
doOperations.push(sbData.doOperations[0], sbData.doOperations[1]);
undoOperations.splice(0, 0, sbData.undoOperations[0], sbData.undoOperations[1]);
} else if (oldSourceParentElement && oldSourceParentElement.classList.contains("protyle-wysiwyg") && oldSourceParentElement.innerHTML === "") {
/// #if !MOBILE
// 拖拽后,根文档原内容为空,且不为悬浮窗
const protyleElement = hasClosestByClassName(oldSourceParentElement, "protyle", true);
if (protyleElement && !protyleElement.classList.contains("block__edit")) {
@ -229,6 +232,7 @@ const dragSb = (protyle: IProtyle, sourceElements: Element[], targetElement: Ele
});
}
}
/// #endif
}
if (isSameDoc) {
transaction(protyle, doOperations, undoOperations);
@ -487,6 +491,7 @@ const dragSame = (protyle: IProtyle, sourceElements: Element[], targetElement: E
doOperations.push(sbData.doOperations[0], sbData.doOperations[1]);
undoOperations.splice(0, 0, sbData.undoOperations[0], sbData.undoOperations[1]);
} else if (oldSourceParentElement && oldSourceParentElement.classList.contains("protyle-wysiwyg") && oldSourceParentElement.childElementCount === 0) {
/// #if !MOBILE
// 拖拽后,根文档原内容为空,且不为悬浮窗
const protyleElement = hasClosestByClassName(oldSourceParentElement, "protyle", true);
if (protyleElement && !protyleElement.classList.contains("block__edit")) {
@ -505,6 +510,7 @@ const dragSame = (protyle: IProtyle, sourceElements: Element[], targetElement: E
});
}
}
/// #endif
}
if (isSameDoc) {
transaction(protyle, doOperations, undoOperations);
@ -636,6 +642,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
dragSame(protyle, sourceElements, targetElement, targetClass.includes("dragover__bottom"));
}
}
/// #if !MOBILE
if (isBacklink) {
setTimeout(() => {
// 等待 drag transaction
@ -644,6 +651,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
});
}, 200);
}
/// #endif
} else if (window.siyuan.dragElement && window.siyuan.dragElement.getAttribute("data-type") === "navigation-file" && targetElement) {
// 文件树拖拽
fetchPost("/api/filetree/doc2Heading", {
@ -661,8 +669,10 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
size: Constants.SIZE_GET,
}, getResponse => {
onGet(getResponse, protyle);
/// #if !MOBILE
// 文档标题互转后,需更新大纲
updatePanelByEditor(protyle, false, false, true);
/// #endif
// 文档标题互转后,编辑区会跳转到开头 https://github.com/siyuan-note/siyuan/issues/2939
setTimeout(() => {
protyle.contentElement.scrollTop = scrollTop;

View file

@ -19,7 +19,6 @@ import {getSearch, isMobile} from "../../util/functions";
import {isLocalPath, pathPosix} from "../../util/pathName";
import {genEmptyElement} from "../../block/util";
import {previewImage} from "../preview/image";
import {openGlobalSearch} from "../../search/util";
import {contentMenu, imgMenu, linkMenu, refMenu, setFold, zoomOut} from "../../menus/protyle";
import * as dayjs from "dayjs";
import {dropEvent} from "../util/editorCommonEvent";
@ -49,6 +48,7 @@ import {blockRender} from "../markdown/blockRender";
import {getAllModels} from "../../layout/getAll";
import {pushBack} from "../../util/backForward";
import {openAsset, openBy, openFileById} from "../../editor/util";
import {openGlobalSearch} from "../../search/util";
/// #endif
import {BlockPanel} from "../../block/Panel";
import {isCtrl} from "../util/compatibility";
@ -1483,12 +1483,14 @@ export class WYSIWYG {
return;
}
/// #if !MOBILE
const tagElement = hasClosestByAttribute(event.target, "data-type", "tag");
if (tagElement && !window.siyuan.altIsPressed && protyle.model) {
openGlobalSearch(`#${tagElement.textContent}#`, !window.siyuan.ctrlIsPressed);
hideElements(["dialog"]);
return;
}
/// #endif
const embedItemElement = hasClosestByClassName(event.target, "protyle-wysiwyg__embed");
if (embedItemElement) {

View file

@ -38,6 +38,10 @@ import {isLocalPath} from "../../util/pathName";
import {clipboard} from "electron";
import {getCurrentWindow} from "@electron/remote";
/// #endif
/// #if !MOBILE
import {openBy, openFileById} from "../../editor/util";
import {commonHotkey} from "./commonHotkey";
/// #endif
import {linkMenu, refMenu, setFold, zoomOut} from "../../menus/protyle";
import {setPosition} from "../../util/setPosition";
import {removeEmbed} from "./removeEmbed";
@ -48,11 +52,9 @@ import {bindMenuKeydown} from "../../menus/Menu";
import {fetchPost} from "../../util/fetch";
import {onGet} from "../util/onGet";
import {scrollCenter} from "../../util/highlightById";
import {openBy, openFileById} from "../../editor/util";
import {BlockPanel} from "../../block/Panel";
import * as dayjs from "dayjs";
import {highlightRender} from "../markdown/highlightRender";
import {commonHotkey} from "./commonHotkey";
import {countBlockWord} from "../../layout/status";
export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
@ -813,11 +815,11 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
event.preventDefault();
return true;
}
/// #if !MOBILE
if (commonHotkey(protyle, event)) {
return true;
}
/// #endif
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockRef.custom, event)) {
const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
let actionElement;
@ -1404,6 +1406,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
}
}
/// #if !MOBILE
const refElement = hasClosestByAttribute(range.startContainer, "data-type", "block-ref");
if (refElement) {
const id = refElement.getAttribute("data-id");
@ -1448,8 +1451,9 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return true;
}
}
/// #endif
/// #if !BROWSER
/// #if !BROWSER && !MOBILE
if (matchHotKey(window.siyuan.config.keymap.editor.general.pasteAsPlainText.custom, event)) {
writeText(clipboard.readText());
setTimeout(() => {