mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 09:00:12 +01:00
This commit is contained in:
parent
1dc5a371f6
commit
5fac682e6f
13 changed files with 120 additions and 111 deletions
|
|
@ -3,7 +3,7 @@ import * as path from "path";
|
|||
/// #endif
|
||||
import {matchHotKey} from "../../protyle/util/hotKey";
|
||||
import {fetchPost} from "../../util/fetch";
|
||||
import {openFileById} from "../../editor/util";
|
||||
import {checkFold, openFileById} from "../../editor/util";
|
||||
import {Constants} from "../../constants";
|
||||
import {newFileByName} from "../../util/newFile";
|
||||
import {App} from "../../index";
|
||||
|
|
@ -90,19 +90,18 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
|
|||
if (!isAsset) {
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) {
|
||||
const id = currentList.getAttribute("data-node-id");
|
||||
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] :
|
||||
(id === currentList.getAttribute("data-root-id") ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ROOTSCROLL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]),
|
||||
zoomIn: foldResponse.data
|
||||
action,
|
||||
zoomIn
|
||||
});
|
||||
if (dialog) {
|
||||
dialog.destroy({focus: "false"});
|
||||
}
|
||||
});
|
||||
})
|
||||
return true;
|
||||
}
|
||||
const id = currentList.getAttribute("data-node-id");
|
||||
|
|
@ -197,18 +196,17 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
|
|||
replace(element, config, edit, false);
|
||||
} else {
|
||||
const id = currentList.getAttribute("data-node-id");
|
||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||
checkFold(id, (zoomIn, action) => {
|
||||
openFileById({
|
||||
app,
|
||||
id,
|
||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] :
|
||||
(id === currentList.getAttribute("data-root-id") ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ROOTSCROLL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]),
|
||||
zoomIn: foldResponse.data
|
||||
action,
|
||||
zoomIn
|
||||
});
|
||||
if (dialog) {
|
||||
dialog.destroy({focus: "false"});
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
} else {
|
||||
/// #if !BROWSER
|
||||
|
|
|
|||
|
|
@ -75,9 +75,9 @@ export abstract class Constants {
|
|||
public static readonly CB_GET_ALL = "cb-get-all"; // 获取所有块
|
||||
public static readonly CB_GET_BACKLINK = "cb-get-backlink"; // 悬浮窗为传递型需展示上下文
|
||||
public static readonly CB_GET_UNUNDO = "cb-get-unundo"; // 不需要记录历史
|
||||
public static readonly CB_GET_SCROLL = "cb-get-scroll"; // 滚动到指定位置
|
||||
public static readonly CB_GET_SCROLL = "cb-get-scroll"; // 滚动到指定位置,用于直接打开文档,必有 rootID
|
||||
public static readonly CB_GET_CONTEXT = "cb-get-context"; // 包含上下文
|
||||
public static readonly CB_GET_ROOTSCROLL = "cb-get-rootscroll"; // 如果为 rootID 就滚动到指定位置
|
||||
public static readonly CB_GET_ROOTSCROLL = "cb-get-rootscroll"; // 如果为 rootID 就滚动到指定位置,必有 rootID
|
||||
public static readonly CB_GET_HTML = "cb-get-html"; // 直接渲染,不需要再 /api/block/getDocInfo,否则搜索表格无法定位
|
||||
public static readonly CB_GET_HISTORY = "cb-get-history"; // 历史渲染
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export class Editor extends Model {
|
|||
app: App,
|
||||
tab: Tab,
|
||||
blockId: string,
|
||||
rootId?: string, // 使用 rootId 会优先使用本地 filepositon 定位
|
||||
rootId: string,
|
||||
mode?: TEditorMode,
|
||||
action?: string[],
|
||||
}) {
|
||||
|
|
@ -38,7 +38,7 @@ export class Editor extends Model {
|
|||
private initProtyle(options: {
|
||||
blockId: string,
|
||||
action?: string[]
|
||||
rootId?: string,
|
||||
rootId: string,
|
||||
mode?: TEditorMode,
|
||||
}) {
|
||||
this.editor = new Protyle(this.app, this.element, {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,15 @@ import {Search} from "../search";
|
|||
import {App} from "../index";
|
||||
import {newCardModel} from "../card/newCardTab";
|
||||
|
||||
export const checkFold = (id: string, cb: (zoomIn: boolean, action: string[]) => void) => {
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||
cb(foldResponse.data, foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL])
|
||||
});
|
||||
}
|
||||
|
||||
export const openFileById = async (options: {
|
||||
app: App,
|
||||
id: string,
|
||||
|
|
@ -472,6 +481,7 @@ const newTab = (options: IOpenFileOptions) => {
|
|||
app: options.app,
|
||||
tab,
|
||||
blockId: options.id,
|
||||
rootId: options.rootID,
|
||||
action: [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS],
|
||||
});
|
||||
} else {
|
||||
|
|
@ -479,6 +489,7 @@ const newTab = (options: IOpenFileOptions) => {
|
|||
app: options.app,
|
||||
tab,
|
||||
blockId: options.id,
|
||||
rootId: options.rootID,
|
||||
mode: options.mode,
|
||||
action: options.action,
|
||||
});
|
||||
|
|
@ -538,7 +549,7 @@ export const updatePanelByEditor = (options: {
|
|||
updateOutline(models, options.protyle, options.reload);
|
||||
updateBacklinkGraph(models, options.protyle);
|
||||
options.protyle.app.plugins.forEach(item => {
|
||||
item.eventBus.emit("switch-protyle", {protyle:options.protyle});
|
||||
item.eventBus.emit("switch-protyle", {protyle: options.protyle});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -466,7 +466,7 @@ export class Wnd {
|
|||
openFileById({
|
||||
app: this.app,
|
||||
id: keepCursorId,
|
||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]
|
||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
||||
});
|
||||
}
|
||||
currentTab.headElement.removeAttribute("keep-cursor");
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ import {setPanelFocus} from "../util";
|
|||
import {getDockByType} from "../tabUtil";
|
||||
import {fetchPost} from "../../util/fetch";
|
||||
import {updateHotkeyTip} from "../../protyle/util/compatibility";
|
||||
import {openFileById} from "../../editor/util";
|
||||
import {Constants} from "../../constants";
|
||||
import {checkFold, openFileById} from "../../editor/util";
|
||||
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
|
||||
import {openBookmarkMenu} from "../../menus/bookmark";
|
||||
import {App} from "../../index";
|
||||
|
|
@ -84,44 +83,54 @@ export class Bookmark extends Model {
|
|||
return;
|
||||
}
|
||||
}
|
||||
const id = element.getAttribute("data-node-id");
|
||||
if (id) {
|
||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||
const id = element.getAttribute("data-node-id")
|
||||
checkFold(id, (zoomIn, action: string[]) => {
|
||||
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
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
rightClick: (element: HTMLElement, event: MouseEvent) => {
|
||||
openBookmarkMenu(element, event, this);
|
||||
},
|
||||
ctrlClick(element: HTMLElement) {
|
||||
ctrlClick: (element: HTMLElement) => {
|
||||
const id = element.getAttribute("data-node-id")
|
||||
checkFold(id, (zoomIn, action: string[]) => {
|
||||
openFileById({
|
||||
app,
|
||||
id: element.getAttribute("data-node-id"),
|
||||
id,
|
||||
keepCursor: true,
|
||||
action: [Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]
|
||||
action,
|
||||
zoomIn
|
||||
});
|
||||
})
|
||||
},
|
||||
altClick(element: HTMLElement) {
|
||||
altClick: (element: HTMLElement,) => {
|
||||
const id = element.getAttribute("data-node-id")
|
||||
checkFold(id, (zoomIn, action: string[]) => {
|
||||
openFileById({
|
||||
app,
|
||||
id: element.getAttribute("data-node-id"),
|
||||
position: "right",
|
||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]
|
||||
});
|
||||
},
|
||||
shiftClick(element: HTMLElement) {
|
||||
openFileById({
|
||||
app,
|
||||
id: element.getAttribute("data-node-id"),
|
||||
id,
|
||||
position: "bottom",
|
||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]
|
||||
action,
|
||||
zoomIn
|
||||
});
|
||||
})
|
||||
},
|
||||
shiftClick: (element: HTMLElement) => {
|
||||
const id = element.getAttribute("data-node-id")
|
||||
checkFold(id, (zoomIn, action: string[]) => {
|
||||
openFileById({
|
||||
app,
|
||||
id,
|
||||
position: "bottom",
|
||||
action,
|
||||
zoomIn
|
||||
});
|
||||
})
|
||||
},
|
||||
blockExtHTML: '<span class="b3-list-item__action"><svg><use xlink:href="#iconMore"></use></svg></span>',
|
||||
topExtHTML: '<span class="b3-list-item__action"><svg><use xlink:href="#iconMore"></use></svg></span>',
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import {addScript} from "../../protyle/util/addScript";
|
|||
import {BlockPanel} from "../../block/Panel";
|
||||
import {fullscreen} from "../../protyle/breadcrumb/action";
|
||||
import {fetchPost} from "../../util/fetch";
|
||||
import {isCurrentEditor, openFileById} from "../../editor/util";
|
||||
import {checkFold, isCurrentEditor, openFileById} from "../../editor/util";
|
||||
import {updateHotkeyTip} from "../../protyle/util/compatibility";
|
||||
import {openGlobalSearch} from "../../search/util";
|
||||
import {App} from "../../index";
|
||||
|
|
@ -652,19 +652,25 @@ export class Graph extends Model {
|
|||
return;
|
||||
}
|
||||
if (window.siyuan.shiftIsPressed) {
|
||||
checkFold(node.id, (zoomIn, action: string[]) => {
|
||||
openFileById({
|
||||
app: this.app,
|
||||
id: node.id,
|
||||
position: "bottom",
|
||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]
|
||||
action,
|
||||
zoomIn
|
||||
});
|
||||
})
|
||||
} else if (window.siyuan.altIsPressed) {
|
||||
checkFold(node.id, (zoomIn, action: string[]) => {
|
||||
openFileById({
|
||||
app: this.app,
|
||||
id: node.id,
|
||||
position: "right",
|
||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]
|
||||
action,
|
||||
zoomIn
|
||||
});
|
||||
})
|
||||
} else if (window.siyuan.ctrlIsPressed) {
|
||||
window.siyuan.blockPanels.push(new BlockPanel({
|
||||
app: this.app,
|
||||
|
|
@ -674,11 +680,14 @@ export class Graph extends Model {
|
|||
nodeIds: [node.id],
|
||||
}));
|
||||
} else {
|
||||
checkFold(node.id, (zoomIn, action: string[]) => {
|
||||
openFileById({
|
||||
app: this.app,
|
||||
id: node.id,
|
||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]
|
||||
action,
|
||||
zoomIn
|
||||
});
|
||||
})
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
|
|
|
|||
|
|
@ -235,7 +235,8 @@ export const copyTab = (app: App, tab: Tab) => {
|
|||
model = new Editor({
|
||||
app,
|
||||
tab: newTab,
|
||||
blockId: tab.model.editor.protyle.block.id
|
||||
blockId: tab.model.editor.protyle.block.id,
|
||||
rootId: tab.model.editor.protyle.block.rootID
|
||||
});
|
||||
} else if (tab.model instanceof Asset) {
|
||||
model = new Asset({
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_
|
|||
} else {
|
||||
window.siyuan.mobile.editor = new Protyle(app, document.getElementById("editor"), {
|
||||
blockId: id,
|
||||
rootId: data.data.rootID,
|
||||
action,
|
||||
render: {
|
||||
scroll: true,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import {syncGuide} from "../../sync/syncGuide";
|
|||
import {Inbox} from "../../layout/dock/Inbox";
|
||||
import {App} from "../../index";
|
||||
import {setTitle} from "../../dialog/processSystem";
|
||||
import {checkFold} from "../../editor/util";
|
||||
|
||||
export const initFramework = (app: App, isStart: boolean) => {
|
||||
setInlineStyle();
|
||||
|
|
@ -134,7 +135,9 @@ export const initFramework = (app: App, isStart: boolean) => {
|
|||
} else {
|
||||
fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {
|
||||
if (response.data.length !== 0) {
|
||||
openMobileFileById(app, response.data[0].id, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
|
||||
checkFold(response.data[0].id, (zoomIn) => {
|
||||
openMobileFileById(app, response.data[0].id, zoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
|
||||
});
|
||||
} else {
|
||||
setEmpty(app);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -228,44 +228,22 @@ export class Protyle {
|
|||
removeLoading(this.protyle);
|
||||
return;
|
||||
}
|
||||
const filePosition = window.siyuan.storage[Constants.LOCAL_FILEPOSITION][options.blockId] ||
|
||||
window.siyuan.storage[Constants.LOCAL_FILEPOSITION][options.rootId];
|
||||
|
||||
if (this.protyle.options.mode !== "preview" &&
|
||||
!mergedOptions.action.includes(Constants.CB_GET_ALL) &&
|
||||
(mergedOptions.action.includes(Constants.CB_GET_SCROLL) || mergedOptions.action.includes(Constants.CB_GET_ROOTSCROLL)) &&
|
||||
filePosition) {
|
||||
options.rootId && window.siyuan.storage[Constants.LOCAL_FILEPOSITION][options.rootId] &&
|
||||
(
|
||||
mergedOptions.action.includes(Constants.CB_GET_SCROLL) ||
|
||||
(mergedOptions.action.includes(Constants.CB_GET_ROOTSCROLL) && options.rootId === options.blockId)
|
||||
)
|
||||
) {
|
||||
getDocByScroll({
|
||||
protyle: this.protyle,
|
||||
scrollAttr: filePosition,
|
||||
scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][options.rootId],
|
||||
mergedOptions,
|
||||
cb: () => {
|
||||
this.afterOnGet(mergedOptions);
|
||||
}
|
||||
});
|
||||
} else if (this.protyle.options.mode !== "preview" &&
|
||||
(mergedOptions.action.includes(Constants.CB_GET_SCROLL) || mergedOptions.action.includes(Constants.CB_GET_ROOTSCROLL))) {
|
||||
fetchPost("/api/block/getDocInfo", {
|
||||
id: options.blockId
|
||||
}, (response) => {
|
||||
if (!mergedOptions.action.includes(Constants.CB_GET_SCROLL) &&
|
||||
response.data.rootID !== options.blockId && mergedOptions.action.includes(Constants.CB_GET_ROOTSCROLL)) {
|
||||
// 打开根文档保持上一次历史,否则按照原有 action 执行 https://github.com/siyuan-note/siyuan/issues/9082
|
||||
this.getDoc(mergedOptions);
|
||||
return;
|
||||
}
|
||||
if (window.siyuan.storage[Constants.LOCAL_FILEPOSITION][response.data.rootID]) {
|
||||
getDocByScroll({
|
||||
protyle: this.protyle,
|
||||
scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][response.data.rootID],
|
||||
mergedOptions,
|
||||
cb: () => {
|
||||
this.afterOnGet(mergedOptions);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.getDoc(mergedOptions);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.getDoc(mergedOptions);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import * as path from "path";
|
|||
import {Constants} from "../constants";
|
||||
import {escapeAriaLabel, escapeGreat, escapeHtml} from "../util/escape";
|
||||
import {fetchPost} from "../util/fetch";
|
||||
import {openFile, openFileById} from "../editor/util";
|
||||
import {checkFold, openFile, openFileById} from "../editor/util";
|
||||
import {showMessage} from "../dialog/message";
|
||||
import {reloadProtyle} from "../protyle/util/reload";
|
||||
import {MenuItem} from "../menus/Menu";
|
||||
|
|
@ -865,19 +865,18 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
} else {
|
||||
if (event.altKey) {
|
||||
const id = target.getAttribute("data-node-id");
|
||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||
checkFold(id, (zoomIn, action) => {
|
||||
openFileById({
|
||||
app,
|
||||
id,
|
||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] :
|
||||
(id === target.getAttribute("data-root-id") ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ROOTSCROLL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]),
|
||||
zoomIn: foldResponse.data,
|
||||
action,
|
||||
zoomIn,
|
||||
position: "right"
|
||||
});
|
||||
if (closeCB) {
|
||||
closeCB();
|
||||
}
|
||||
});
|
||||
})
|
||||
} else if (!target.classList.contains("b3-list-item--focus")) {
|
||||
searchPanelElement.querySelector(".b3-list-item--focus").classList.remove("b3-list-item--focus");
|
||||
target.classList.add("b3-list-item--focus");
|
||||
|
|
@ -906,18 +905,17 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
/// #endif
|
||||
} else {
|
||||
const id = target.getAttribute("data-node-id");
|
||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||
checkFold(id, (zoomIn, action) => {
|
||||
openFileById({
|
||||
app,
|
||||
id,
|
||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] :
|
||||
(id === target.getAttribute("data-root-id") ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ROOTSCROLL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]),
|
||||
zoomIn: foldResponse.data
|
||||
action,
|
||||
zoomIn
|
||||
});
|
||||
if (closeCB) {
|
||||
closeCB();
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
window.siyuan.menus.menu.remove();
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ const focusStack = async (app: App, stack: IBackStack) => {
|
|||
app: app,
|
||||
tab,
|
||||
blockId: stack.zoomId || stack.protyle.block.rootID,
|
||||
rootId: stack.protyle.block.rootID,
|
||||
action: stack.zoomId ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS]
|
||||
});
|
||||
tab.addModel(editor);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue