♻️ context

This commit is contained in:
Vanessa 2022-08-07 09:26:08 +08:00
parent 3ef5731cb9
commit 65821e57de
22 changed files with 50 additions and 45 deletions

View file

@ -51,6 +51,7 @@ export abstract class Constants {
public static readonly CB_GET_ALL = "cb-get-all"; // 获取所有块
public static readonly CB_GET_UNUNDO = "cb-get-unundo"; // 不需要记录历史
public static readonly CB_GET_SCROLL = "cb-get-scroll"; // 滚动到指定位置
public static readonly CB_GET_CONTEXT = "cb-get-context"; // 包含上下文
// localstorage
public static readonly LOCAL_SEARCHEDATA = "local-searchedata";

View file

@ -198,7 +198,7 @@ const switchEditor = (editor: Editor, options: IOpenFileOptions, allModels: IMod
if ((!nodeElement || nodeElement?.clientHeight === 0) && options.id !== options.rootID) {
fetchPost("/api/filetree/getDoc", {
id: options.id,
mode: (options.action && !options.action.includes(Constants.CB_GET_ALL)) ? 3 : 0,
mode: (options.action && options.action.includes(Constants.CB_GET_CONTEXT)) ? 3 : 0,
size: Constants.SIZE_GET,
}, getResponse => {
onGet(getResponse, editor.editor.protyle, options.action);

View file

@ -334,7 +334,7 @@ export class Wnd {
} else {
openFileById({
id: keepCursorId,
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
}
currentTab.headElement.removeAttribute("keep-cursor");

View file

@ -137,27 +137,28 @@ export class Backlinks extends Model {
click(element: HTMLElement) {
openFileById({
id: element.getAttribute("data-node-id"),
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
},
ctrlClick(element: HTMLElement) {
openFileById({
id: element.getAttribute("data-node-id"),
keepCursor: true,
action: [Constants.CB_GET_CONTEXT]
});
},
altClick(element: HTMLElement) {
openFileById({
id: element.getAttribute("data-node-id"),
position: "right",
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
},
shiftClick(element: HTMLElement) {
openFileById({
id: element.getAttribute("data-node-id"),
position: "bottom",
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
}
});
@ -187,7 +188,7 @@ export class Backlinks extends Model {
} else {
openFileById({
id: element.getAttribute("data-node-id"),
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
}
},
@ -195,20 +196,21 @@ export class Backlinks extends Model {
openFileById({
id: element.getAttribute("data-node-id"),
keepCursor: true,
action: [Constants.CB_GET_CONTEXT]
});
},
altClick(element: HTMLElement) {
openFileById({
id: element.getAttribute("data-node-id"),
position: "right",
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
},
shiftClick(element: HTMLElement) {
openFileById({
id: element.getAttribute("data-node-id"),
position: "bottom",
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
},
blockExtHTML: `<span class="b3-list-item__action b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.more}"><svg><use xlink:href="#iconMore"></use></svg></span>`

View file

@ -80,7 +80,7 @@ export class Bookmark extends Model {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({
id,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
});
});
},
@ -152,20 +152,21 @@ export class Bookmark extends Model {
openFileById({
id: element.getAttribute("data-node-id"),
keepCursor: true,
action: [Constants.CB_GET_CONTEXT]
});
},
altClick(element: HTMLElement) {
openFileById({
id: element.getAttribute("data-node-id"),
position: "right",
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
},
shiftClick(element: HTMLElement) {
openFileById({
id: element.getAttribute("data-node-id"),
position: "bottom",
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
}
});

View file

@ -598,13 +598,13 @@ export class Graph extends Model {
openFileById({
id: node.id,
position: "bottom",
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
} else if (window.siyuan.altIsPressed) {
openFileById({
id: node.id,
position: "right",
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
} else if (window.siyuan.ctrlIsPressed) {
window.siyuan.blockPanels.push(new BlockPanel({
@ -612,7 +612,7 @@ export class Graph extends Model {
nodeIds: [node.id],
}));
} else {
openFileById({id: node.id, action: [Constants.CB_GET_FOCUS]});
openFileById({id: node.id, action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]});
}
});
}, 1000);

View file

@ -96,7 +96,7 @@ export class Outline extends Model {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({
id,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT],
});
});
}

View file

@ -89,7 +89,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
openFileById({
id: refBlockId,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
keepCursor: true,
zoomIn: foldResponse.data
});
@ -105,7 +105,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
openFileById({
id: refBlockId,
position: "right",
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data
});
});
@ -120,7 +120,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
openFileById({
id: refBlockId,
position: "bottom",
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data
});
});
@ -354,7 +354,7 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB
if (window.siyuan.mobileEditor) {
window.localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({
id,
action: id === protyle.block.rootID ? [Constants.CB_GET_HL] : [Constants.CB_GET_ALL]
action: id === protyle.block.rootID ? [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT] : [Constants.CB_GET_ALL]
}));
window.siyuan.backStack.push({
id: protyle.block.id,

View file

@ -53,7 +53,7 @@ export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL], p
fetchPost("/api/filetree/getDoc", {
id,
size: action.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
mode: !action.includes(Constants.CB_GET_ALL) ? 3 : 0,
mode: action.includes(Constants.CB_GET_CONTEXT) ? 3 : 0,
}, getResponse => {
onGet(getResponse, window.siyuan.mobileEditor.protyle, action);
window.siyuan.mobileEditor.protyle.breadcrumb.render(window.siyuan.mobileEditor.protyle);

View file

@ -46,7 +46,7 @@ export class MobileBacklinks {
element: this.element.querySelector(".backlinkList") as HTMLElement,
data: null,
click(element: HTMLElement) {
openMobileFileById(element.getAttribute("data-node-id"), [Constants.CB_GET_FOCUS]);
openMobileFileById(element.getAttribute("data-node-id"), [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
}
});
this.mTree = new Tree({
@ -73,7 +73,7 @@ export class MobileBacklinks {
}).element);
window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY});
} else {
openMobileFileById(element.getAttribute("data-node-id"), [Constants.CB_GET_FOCUS]);
openMobileFileById(element.getAttribute("data-node-id"), [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
}
},
blockExtHTML: '<span class="b3-list-item__action"><svg><use xlink:href="#iconMore"></use></svg></span>'

View file

@ -83,7 +83,7 @@ export class MobileBookmarks {
});
}
} else {
openMobileFileById(id, [Constants.CB_GET_FOCUS]);
openMobileFileById(id, [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
}
},
blockExtHTML: '<span class="b3-list-item__action" data-type="remove"><svg><use xlink:href="#iconTrashcan"></use></svg></span>',

View file

@ -29,7 +29,7 @@ export class MobileOutline {
click: (element: HTMLElement) => {
const id = element.getAttribute("data-node-id");
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openMobileFileById(id,foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID]);
openMobileFileById(id, foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT]);
});
}
});

View file

@ -118,7 +118,7 @@ export const initFramework = () => {
} else {
fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {
if (response.data.length !== 0) {
openMobileFileById(response.data[0].id);
openMobileFileById(response.data[0].id, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
} else {
setEmpty();
}

View file

@ -80,7 +80,7 @@ export const popSearch = (modelElement: HTMLElement, modelMainElement: HTMLEleme
preventScroll(window.siyuan.mobileEditor.protyle);
}
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openMobileFileById(id,foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL]);
openMobileFileById(id,foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
});
closePanel();
event.preventDefault();

View file

@ -506,11 +506,11 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
}, () => {
insertHTML(genEmptyBlock(false, false, `<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">Untitled</span>`), protyle);
/// #if MOBILE
openMobileFileById(newSubDocId);
openMobileFileById(newSubDocId, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
/// #else
openFileById({
id: newSubDocId,
action: [Constants.CB_GET_HL]
action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]
});
/// #endif
});

View file

@ -157,7 +157,7 @@ class Protyle {
fetchPost("/api/filetree/getDoc", {
id: options.blockId,
k: options.key || "",
mode: (options.action && !options.action.includes(Constants.CB_GET_ALL)) ? 3 : 0, // 0: 仅当前 ID默认值1向上 2向下3上下都加载4加载最后
mode: (options.action && options.action.includes(Constants.CB_GET_CONTEXT)) ? 3 : 0, // 0: 仅当前 ID默认值1向上 2向下3上下都加载4加载最后
size: options.action?.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
}, getResponse => {
onGet(getResponse, this.protyle, options.action);

View file

@ -1357,33 +1357,33 @@ export class WYSIWYG {
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
/// #if MOBILE
openMobileFileById(refBlockId, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL]);
openMobileFileById(refBlockId, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
/// #else
if (window.siyuan.shiftIsPressed) {
openFileById({
id: refBlockId,
position: "bottom",
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data
});
} else if (window.siyuan.altIsPressed) {
openFileById({
id: refBlockId,
position: "right",
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data
});
} else if (window.siyuan.ctrlIsPressed) {
openFileById({
id: refBlockId,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
keepCursor: true,
zoomIn: foldResponse.data
});
} else {
openFileById({
id: refBlockId,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data
});
}

View file

@ -1533,6 +1533,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
openFileById({
id,
keepCursor: true,
action: [Constants.CB_GET_CONTEXT]
});
event.preventDefault();
event.stopPropagation();
@ -1541,7 +1542,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
openFileById({
id,
position: "right",
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
event.preventDefault();
event.stopPropagation();
@ -1550,7 +1551,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
openFileById({
id,
position: "bottom",
action: [Constants.CB_GET_FOCUS]
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
});
event.preventDefault();
event.stopPropagation();

View file

@ -116,7 +116,7 @@ export class Search extends Model {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({
id,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data,
position: "right",
});
@ -135,7 +135,7 @@ export class Search extends Model {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({
id,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data
});
});
@ -196,7 +196,7 @@ export class Search extends Model {
} else {
this.protyle = new Protyle(this.element.querySelector("#searchPreview") as HTMLElement, {
blockId: id,
action: foldResponse.data ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL],
action: foldResponse.data ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
key: value,
render: {
gutter: true,

View file

@ -468,7 +468,7 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({
id,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data
});
dialog.destroy();
@ -591,7 +591,7 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({
id,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data,
position: "right"
});
@ -614,7 +614,7 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({
id,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS],
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data
});
dialog.destroy();
@ -643,7 +643,7 @@ const getArticle = (options: {
if (!protyle) {
protyle = new Protyle(options.dialog.element.querySelector("#searchPreview") as HTMLElement, {
blockId: options.id,
action: foldResponse.data ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL],
action: foldResponse.data ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
key: options.k,
render: {
gutter: true,

View file

@ -67,7 +67,7 @@ export const newFile = (notebookId?: string, currentPath?: string, open?: boolea
}, () => {
/// #if !MOBILE
if (open) {
openFileById({id, action: [Constants.CB_GET_HL]});
openFileById({id, action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]});
}
/// #endif
});

View file

@ -342,7 +342,7 @@ const initWindow = () => {
}
openFileById({
id: url.substr(16, 22),
action: [Constants.CB_GET_FOCUS],
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: getSearch("focus", url) === "1"
});
});