Skip to content

Commit

Permalink
♻️ #9846
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Dec 9, 2023
1 parent db2a3a5 commit 801f665
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 95 deletions.
11 changes: 5 additions & 6 deletions app/src/boot/globalEvent/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {initTabMenu} from "../../menus/tab";
import {getInstanceById} from "../../layout/util";
import {Tab} from "../../layout/Tab";
import {hideTooltip} from "../../dialog/tooltip";
import {fetchPost} from "../../util/fetch";
import {openFileById} from "../../editor/util";
import {checkFold, openFileById} from "../../editor/util";

export const initWindowEvent = (app: App) => {
document.body.addEventListener("mouseleave", () => {
Expand Down Expand Up @@ -131,15 +130,15 @@ export const initWindowEvent = (app: App) => {
if (backlinkBreadcrumbItemElement) {
const breadcrumbId = backlinkBreadcrumbItemElement.getAttribute("data-id") || backlinkBreadcrumbItemElement.getAttribute("data-node-id");
if (breadcrumbId) {
fetchPost("/api/block/checkBlockFold", {id: breadcrumbId}, (foldResponse) => {
checkFold(breadcrumbId, (zoomIn) => {
openFileById({
app,
id: breadcrumbId,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data
action: zoomIn ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn,
});
window.siyuan.menus.menu.remove();
});
})
}
event.stopImmediatePropagation();
event.preventDefault();
Expand Down
8 changes: 4 additions & 4 deletions app/src/boot/onGetConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {appearance} from "../config/appearance";
import {fetchPost, fetchSyncPost} from "../util/fetch";
import {addGA, initAssets, setInlineStyle} from "../util/assets";
import {renderSnippet} from "../config/util/snippets";
import {openFile, openFileById} from "../editor/util";
import {checkFold, openFile, openFileById} from "../editor/util";
import {focusByRange} from "../protyle/util/selection";
import {exitSiYuan} from "../dialog/processSystem";
import {isWindow} from "../util/functions";
Expand Down Expand Up @@ -307,12 +307,12 @@ export const initWindow = async (app: App) => {
const focus = urlObj.searchParams.get("focus") === "1";
fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
if (existResponse.data) {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
checkFold(id, (zoomIn) => {
openFileById({
app,
id,
action: (foldResponse.data || focus) ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
zoomIn: foldResponse.data || focus
action: (zoomIn || focus) ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
zoomIn: zoomIn || focus
});
});
ipcRenderer.send(Constants.SIYUAN_CMD, "show");
Expand Down
5 changes: 3 additions & 2 deletions app/src/layout/dock/Bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {checkFold, openFileById} from "../../editor/util";
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
import {openBookmarkMenu} from "../../menus/bookmark";
import {App} from "../../index";
import {Constants} from "../../constants";

export class Bookmark extends Model {
private openNodes: string[];
Expand Down Expand Up @@ -98,12 +99,12 @@ export class Bookmark extends Model {
},
ctrlClick: (element: HTMLElement) => {
const id = element.getAttribute("data-node-id")
checkFold(id, (zoomIn, action: string[]) => {
checkFold(id, (zoomIn) => {
openFileById({
app,
id,
keepCursor: true,
action,
action: zoomIn ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
zoomIn
});
})
Expand Down
8 changes: 4 additions & 4 deletions app/src/layout/dock/Outline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {fetchPost} from "../../util/fetch";
import {getAllModels} from "../getAll";
import {hasClosestBlock, hasClosestByClassName, hasTopClosestByClassName} from "../../protyle/util/hasClosest";
import {updateHotkeyTip} from "../../protyle/util/compatibility";
import {openFileById} from "../../editor/util";
import {checkFold, openFileById} from "../../editor/util";
import {Constants} from "../../constants";
import {escapeHtml} from "../../util/escape";
import {unicode2Emoji} from "../../emoji";
Expand Down Expand Up @@ -123,13 +123,13 @@ export class Outline extends Model {
});
}
} else {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
checkFold(id, (zoomIn) => {
openFileById({
app: options.app,
id,
action: foldResponse.data ? [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],
action: 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],
});
});
})
}
},
ctrlClick(element: HTMLElement) {
Expand Down
26 changes: 13 additions & 13 deletions app/src/menus/protyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {onGet} from "../protyle/util/onGet";
import {getAllModels} from "../layout/getAll";
import {pasteAsPlainText, pasteEscaped, pasteText} from "../protyle/util/paste";
/// #if !MOBILE
import {openFileById, updateBacklinkGraph} from "../editor/util";
import {checkFold, openFileById, updateBacklinkGraph} from "../editor/util";
import {openGlobalSearch} from "../search/util";
import {openNewWindowById} from "../window/openNewWindow";
/// #endif
Expand Down Expand Up @@ -351,12 +351,12 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
icon: "iconOpen",
accelerator: window.siyuan.config.keymap.editor.general.openBy.custom + "/Click",
click() {
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
checkFold(refBlockId, (zoomIn, action) => {
openFileById({
app: protyle.app,
id: refBlockId,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
zoomIn: foldResponse.data
action,
zoomIn
});
});
}
Expand All @@ -366,13 +366,13 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
icon: "iconEyeoff",
accelerator: window.siyuan.config.keymap.editor.general.refTab.custom + "/⌘Click",
click() {
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
checkFold(refBlockId, (zoomIn) => {
openFileById({
app: protyle.app,
id: refBlockId,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
action: zoomIn ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
keepCursor: true,
zoomIn: foldResponse.data
zoomIn
});
});
}
Expand All @@ -382,13 +382,13 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
icon: "iconLayoutRight",
accelerator: window.siyuan.config.keymap.editor.general.insertRight.custom + "/⌥Click",
click() {
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
checkFold(refBlockId, (zoomIn, action) => {
openFileById({
app: protyle.app,
id: refBlockId,
position: "right",
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
zoomIn: foldResponse.data
action,
zoomIn
});
});
}
Expand All @@ -398,13 +398,13 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
icon: "iconLayoutBottom",
accelerator: window.siyuan.config.keymap.editor.general.insertBottom.custom + (window.siyuan.config.keymap.editor.general.insertBottom.custom ? "/" : "") + "⇧Click",
click() {
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
checkFold(refBlockId, (zoomIn, action) => {
openFileById({
app: protyle.app,
id: refBlockId,
position: "bottom",
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
zoomIn: foldResponse.data
action,
zoomIn
});
});
}
Expand Down
35 changes: 20 additions & 15 deletions app/src/menus/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from "path";
/// #endif
import {fetchPost} from "../util/fetch";
import {getAssetName, pathPosix, showFileInFolder} from "../util/pathName";
import {openFileById} from "../editor/util";
import {checkFold, openFileById} from "../editor/util";
import {Constants} from "../constants";
import {openNewWindowById} from "../window/openNewWindow";
import {MenuItem} from "./Menu";
Expand All @@ -17,7 +17,7 @@ export const exportAsset = (src: string) => {
label: window.siyuan.languages.export,
icon: "iconUpload",
async click() {
const result = await ipcRenderer.invoke(Constants.SIYUAN_GET,{
const result = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
cmd: "showSaveDialog",
defaultPath: getAssetName(src) + pathPosix().extname(src),
properties: ["showOverwriteConfirmation"],
Expand All @@ -41,15 +41,15 @@ export const openEditorTab = (app: App, id: string, notebookId?: string, pathStr
if (notebookId) {
openFileById({app, id, position: "right", action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]});
} else {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
checkFold(id, (zoomIn, action) => {
openFileById({
app,
id,
position: "right",
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
zoomIn: foldResponse.data
action,
zoomIn
});
});
})
}
}
}, {
Expand All @@ -60,15 +60,15 @@ export const openEditorTab = (app: App, id: string, notebookId?: string, pathStr
if (notebookId) {
openFileById({app, id, position: "bottom", action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]});
} else {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
checkFold(id, (zoomIn, action)=> {
openFileById({
app,
id,
position: "bottom",
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
zoomIn: foldResponse.data
action,
zoomIn
});
});
})
}
}
}];
Expand All @@ -78,17 +78,22 @@ export const openEditorTab = (app: App, id: string, notebookId?: string, pathStr
accelerator: "⌥⌘Click",
click: () => {
if (notebookId) {
openFileById({app, id, action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL], removeCurrentTab: false});
openFileById({
app,
id,
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
removeCurrentTab: false
});
} else {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
checkFold(id, (zoomIn, action)=> {
openFileById({
app,
id,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
zoomIn: foldResponse.data,
action,
zoomIn,
removeCurrentTab: false
});
});
})
}
}
});
Expand Down
5 changes: 3 additions & 2 deletions app/src/mobile/dock/MobileBookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {hasClosestByClassName} from "../../protyle/util/hasClosest";
import {openMobileFileById} from "../editor";
import {openBookmarkMenu} from "../../menus/bookmark";
import {App} from "../../index";
import {checkFold, openFileById} from "../../editor/util";

export class MobileBookmarks {
public element: HTMLElement;
Expand Down Expand Up @@ -38,8 +39,8 @@ export class MobileBookmarks {
return;
}
}
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openMobileFileById(app, id, foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
checkFold(id, (zoomIn, action) => {
openMobileFileById(app, id, zoomIn ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
});
},
blockExtHTML: '<span class="b3-list-item__action"><svg><use xlink:href="#iconMore"></use></svg></span>',
Expand Down
5 changes: 3 additions & 2 deletions app/src/mobile/dock/MobileOutline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Constants} from "../../constants";
import {getEventName} from "../../protyle/util/compatibility";
import {App} from "../../index";
import {closePanel} from "../util/closePanel";
import {checkFold} from "../../editor/util";

export class MobileOutline {
private tree: Tree;
Expand Down Expand Up @@ -33,8 +34,8 @@ export class MobileOutline {
closePanel();
document.getElementById(id)?.scrollIntoView();
} else {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openMobileFileById(app, id, foldResponse.data ? [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]);
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]);
});
}
}
Expand Down
7 changes: 4 additions & 3 deletions app/src/mobile/menu/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
renderPreview,
} from "../../search/assets";
import {addClearButton} from "../../util/addClearButton";
import {checkFold} from "../../editor/util";

const replace = (element: Element, config: ISearchOption, isAll: boolean) => {
if (config.method === 1 || config.method === 2) {
Expand Down Expand Up @@ -573,8 +574,8 @@ const initSearchEvent = (app: App, element: Element, config: ISearchOption) => {
if (window.siyuan.mobile.editor.protyle) {
preventScroll(window.siyuan.mobile.editor.protyle);
}
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openMobileFileById(app, id, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
checkFold(id, (zoomIn) => {
openMobileFileById(app, id, zoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
});
closePanel();
} else {
Expand Down Expand Up @@ -717,7 +718,7 @@ const goAsset = () => {
assetInputEvent(assetsElement, localSearch);
addClearButton({
inputElement,
className:"toolbar__icon",
className: "toolbar__icon",
clearCB() {
assetInputEvent(assetsElement, localSearch);
}
Expand Down
Loading

0 comments on commit 801f665

Please sign in to comment.