Vanessa 2024-04-30 22:41:43 +08:00
parent 733014b266
commit 719803bff6
4 changed files with 53 additions and 23 deletions

View file

@ -8,7 +8,7 @@ import {Constants} from "../constants";
import {hideElements} from "../protyle/ui/hideElements"; import {hideElements} from "../protyle/ui/hideElements";
import {blockRender} from "../protyle/render/blockRender"; import {blockRender} from "../protyle/render/blockRender";
import {fetchPost} from "../util/fetch"; import {fetchPost} from "../util/fetch";
import {zoomOut} from "../menus/protyle"; import {openFileById} from "../editor/util";
export const cancelSB = (protyle: IProtyle, nodeElement: Element) => { export const cancelSB = (protyle: IProtyle, nodeElement: Element) => {
const doOperations: IOperation[] = []; const doOperations: IOperation[] = [];
@ -74,25 +74,18 @@ export const genSBElement = (layout: string, id?: string, attrHTML?: string) =>
return sbElement; return sbElement;
}; };
export const jumpToParentNext = (protyle: IProtyle, nodeElement: Element) => { export const jumpToParent = (protyle: IProtyle, nodeElement: Element, type: "parent" | "next" | "previous") => {
const topElement = getTopAloneElement(nodeElement); fetchPost("/api/block/getBlockSiblingID", {id: nodeElement.getAttribute("data-node-id")}, (response) => {
if (topElement) { const targetId = response.data[type];
const topParentElement = hasClosestByClassName(topElement, "list") || hasClosestByClassName(topElement, "bq") || hasClosestByClassName(topElement, "sb") || topElement; if (!targetId) {
const nextElement = getNextBlock(topParentElement); return;
if (nextElement) {
focusBlock(nextElement);
scrollCenter(protyle, nextElement);
} else {
fetchPost("/api/block/getParentNextChildID", {id: nodeElement.getAttribute("data-node-id")}, (response) => {
if (response.data.id) {
zoomOut({
protyle,
id: response.data.id,
});
}
});
} }
} openFileById({
app: protyle.app,
id: targetId,
action: [Constants.CB_GET_FOCUS]
})
});
}; };
export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, id?: string) => { export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, id?: string) => {

View file

@ -399,6 +399,8 @@ export abstract class Constants {
insertBefore: {default: "⇧⌘B", custom: "⇧⌘B"}, insertBefore: {default: "⇧⌘B", custom: "⇧⌘B"},
insertAfter: {default: "⇧⌘A", custom: "⇧⌘A"}, insertAfter: {default: "⇧⌘A", custom: "⇧⌘A"},
jumpToParentNext: {default: "⇧⌘N", custom: "⇧⌘N"}, jumpToParentNext: {default: "⇧⌘N", custom: "⇧⌘N"},
jumpToParentPrev: {default: "⇧⌘M", custom: "⇧⌘M"},
jumpToParent: {default: "⇧⌘J", custom: "⇧⌘J"},
moveToUp: {default: "⇧⌘↑", custom: "⇧⌘↑"}, moveToUp: {default: "⇧⌘↑", custom: "⇧⌘↑"},
moveToDown: {default: "⇧⌘↓", custom: "⇧⌘↓"} moveToDown: {default: "⇧⌘↓", custom: "⇧⌘↓"}
}, },

View file

@ -28,7 +28,13 @@ import {removeEmbed} from "../wysiwyg/removeEmbed";
import {getContenteditableElement, getTopAloneElement, isNotEditBlock} from "../wysiwyg/getBlock"; import {getContenteditableElement, getTopAloneElement, isNotEditBlock} from "../wysiwyg/getBlock";
import * as dayjs from "dayjs"; import * as dayjs from "dayjs";
import {fetchPost, fetchSyncPost} from "../../util/fetch"; import {fetchPost, fetchSyncPost} from "../../util/fetch";
import {cancelSB, genEmptyElement, getLangByType, insertEmptyBlock, jumpToParentNext} from "../../block/util"; import {
cancelSB,
genEmptyElement,
getLangByType,
insertEmptyBlock,
jumpToParent,
} from "../../block/util";
import {countBlockWord} from "../../layout/status"; import {countBlockWord} from "../../layout/status";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
import {mathRender} from "../render/mathRender"; import {mathRender} from "../render/mathRender";
@ -1630,9 +1636,26 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.editor.general.jumpToParentNext.custom, accelerator: window.siyuan.config.keymap.editor.general.jumpToParentNext.custom,
click() { click() {
hideElements(["select"], protyle); hideElements(["select"], protyle);
jumpToParentNext(protyle, nodeElement); jumpToParent(protyle, nodeElement, "next");
} }
}).element); }).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.jumpToParentPrev,
accelerator: window.siyuan.config.keymap.editor.general.jumpToParentPrev.custom,
click() {
hideElements(["select"], protyle);
jumpToParent(protyle, nodeElement, "previous");
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.jumpToParent,
accelerator: window.siyuan.config.keymap.editor.general.jumpToParent.custom,
click() {
hideElements(["select"], protyle);
jumpToParent(protyle, nodeElement, "parent");
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element); window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
if (type !== "NodeThematicBreak") { if (type !== "NodeThematicBreak") {

View file

@ -35,7 +35,7 @@ import {turnsIntoOneTransaction, turnsIntoTransaction, updateBatchTransaction, u
import {fontEvent} from "../toolbar/Font"; import {fontEvent} from "../toolbar/Font";
import {addSubList, listIndent, listOutdent} from "./list"; import {addSubList, listIndent, listOutdent} from "./list";
import {newFileContentBySelect, rename, replaceFileName} from "../../editor/rename"; import {newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";
import {insertEmptyBlock, jumpToParentNext} from "../../block/util"; import {insertEmptyBlock, jumpToParent} from "../../block/util";
import {isLocalPath} from "../../util/pathName"; import {isLocalPath} from "../../util/pathName";
/// #if !MOBILE /// #if !MOBILE
import {openBy, openFileById, openLink} from "../../editor/util"; import {openBy, openFileById, openLink} from "../../editor/util";
@ -1358,7 +1358,19 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return true; return true;
} }
if (matchHotKey(window.siyuan.config.keymap.editor.general.jumpToParentNext.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.jumpToParentNext.custom, event)) {
jumpToParentNext(protyle, nodeElement); jumpToParent(protyle, nodeElement, "next");
event.preventDefault();
event.stopPropagation();
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.jumpToParent.custom, event)) {
jumpToParent(protyle, nodeElement, "parent");
event.preventDefault();
event.stopPropagation();
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.jumpToParentPrev.custom, event)) {
jumpToParent(protyle, nodeElement, "previous");
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return true;