Vanessa 2024-04-28 21:14:33 +08:00
parent c79e2f79f5
commit cb28d919b6
2 changed files with 45 additions and 11 deletions

View file

@ -33,7 +33,7 @@ import {enter, softEnter} from "./enter";
import {fixTable} from "../util/table";
import {turnsIntoOneTransaction, turnsIntoTransaction, updateBatchTransaction, updateTransaction} from "./transaction";
import {fontEvent} from "../toolbar/Font";
import {listIndent, listOutdent} from "./list";
import {addSubList, listIndent, listOutdent} from "./list";
import {newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";
import {insertEmptyBlock, jumpToParentNext} from "../../block/util";
import {isLocalPath} from "../../util/pathName";
@ -866,16 +866,20 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
}
// 回车
if (!event.altKey && isNotCtrl(event) && event.key === "Enter") {
if (!event.shiftKey) {
enter(nodeElement, range, protyle);
event.stopPropagation();
event.preventDefault();
return;
} else if (nodeElement.getAttribute("data-type") === "NodeAttributeView") {
event.stopPropagation();
event.preventDefault();
return;
if (isNotCtrl(event) && event.key === "Enter") {
if (event.altKey) {
addSubList(protyle, nodeElement, range);
} else {
if (!event.shiftKey) {
enter(nodeElement, range, protyle);
event.stopPropagation();
event.preventDefault();
return;
} else if (nodeElement.getAttribute("data-type") === "NodeAttributeView") {
event.stopPropagation();
event.preventDefault();
return;
}
}
}

View file

@ -4,6 +4,8 @@ import {genEmptyBlock} from "../../block/util";
import * as dayjs from "dayjs";
import {Constants} from "../../constants";
import {moveToPrevious} from "./remove";
import {hasClosestByClassName} from "../util/hasClosest";
import {setFold} from "../../menus/protyle";
export const updateListOrder = (listElement: Element, sIndex?: number) => {
if (listElement.getAttribute("data-subtype") !== "o") {
@ -42,6 +44,34 @@ export const genListItemElement = (listItemElement: Element, offset = 0, wbr = f
return element.content.firstElementChild as HTMLElement;
};
export const addSubList = (protyle: IProtyle, nodeElement: Element, range: Range) => {
const parentItemElement = hasClosestByClassName(nodeElement, "li");
if (!parentItemElement) {
return;
}
const lastSubItem = parentItemElement.querySelector(".list")?.lastElementChild.previousElementSibling;
if (!lastSubItem) {
return;
}
const newListElement = genListItemElement(lastSubItem, 0, true);
const id = newListElement.getAttribute("data-node-id");
lastSubItem.after(newListElement);
if (lastSubItem.parentElement.getAttribute("fold") === "1") {
setFold(protyle, lastSubItem.parentElement, true);
}
transaction(protyle, [{
action: "insert",
id,
data: newListElement.outerHTML,
previousID: lastSubItem.getAttribute("data-node-id"),
}], [{
action: "delete",
id,
}]);
focusByWbr(newListElement, range);
};
export const listIndent = (protyle: IProtyle, liItemElements: Element[], range: Range) => {
const previousElement = liItemElements[0].previousElementSibling as HTMLElement;
if (!previousElement) {