Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/src/protyle/util/hasClosest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,19 @@ export const hasClosestByClassName = (element: Node, className: string, top = fa

export const hasClosestBlock = (element: Node) => {
const nodeElement = hasClosestByAttribute(element, "data-node-id", null);
if (nodeElement && nodeElement.tagName !== "BUTTON" && nodeElement.getAttribute("data-type")?.startsWith("Node")) {
if (isBlockElement(nodeElement)) {
return nodeElement;
}
return false;
};

export const isBlockElement = (element: Element | false | undefined) => {
if (!element) {
return false;
}
return element.hasAttribute("data-node-id") && element.tagName !== "BUTTON" && (element.getAttribute("data-type")?.startsWith("Node") ?? false);
};

export const isInEmbedBlock = (element: Element) => {
const embedElement = hasTopClosestByAttribute(element, "data-type", "NodeBlockQueryEmbed");
if (embedElement) {
Expand Down
55 changes: 36 additions & 19 deletions app/src/protyle/wysiwyg/keydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1072,38 +1072,55 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
}

// 软换行
if (matchHotKey("⇧↩", event) && selectText === "" && softEnter(range, nodeElement, protyle)) {
if (selectText === "" && matchHotKey("⇧↩", event) && softEnter(range, nodeElement, protyle)) {
event.stopPropagation();
event.preventDefault();
return;
}

// 代码块语言选择 https://github.com/siyuan-note/siyuan/issues/14126
if (matchHotKey("⌥↩", event) && selectText === "") {
// 列表插入末尾子项 https://github.com/siyuan-note/siyuan/issues/11164
// 代码块修改语言 https://github.com/siyuan-note/siyuan/issues/14126
// 提示块修改类型和标题 https://github.com/siyuan-note/siyuan/issues/16678
if (selectText === "" && matchHotKey("⌥↩", event) && !isIncludesHotKey("⌥↩")) {
const selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
if (selectElements.length === 0) {
selectElements.push(nodeElement);
}
if (selectElements.length > 0 && !isIncludesHotKey("⌥↩")) {

const codeBlockElements = selectElements.filter(item => {
return item.classList.contains("code-block");
});
if (codeBlockElements.length > 0) {
const languageElements: HTMLElement[] = [];
const calloutElements: HTMLElement[] = [];
codeBlockElements.forEach(item => {
languageElements.push(item.querySelector(".protyle-action__language"));
});
protyle.toolbar.showCodeLanguage(protyle, languageElements);
event.stopPropagation();
event.preventDefault();
return;
}

const liBlockElement = hasClosestByClassName(nodeElement, "li");
if (liBlockElement) {
selectElements.forEach(item => {
if (item.classList.contains("code-block")) {
languageElements.push(item.querySelector(".protyle-action__language"));
} else {
const calloutElement = hasClosestByClassName(item, "callout");
if (calloutElement) {
calloutElements.push(calloutElement);
}
}
item.classList.remove("protyle-wysiwyg--select");
});
if (languageElements.length > 0) {
protyle.toolbar.showCodeLanguage(protyle, languageElements);
} else if (addSubList(protyle, nodeElement, range)) {
// 函数内部已处理
} else if (calloutElements.length > 0) {
updateCalloutType(calloutElements, protyle);
addSubList(protyle, nodeElement, range);
event.stopPropagation();
event.preventDefault();
return;
}

const calloutElements: HTMLElement[] = [];
selectElements.forEach(item => {
const calloutElement = hasClosestByClassName(item, "callout");
if (calloutElement) {
calloutElements.push(calloutElement);
}
});
if (calloutElements.length > 0) {
updateCalloutType(calloutElements, protyle);
event.stopPropagation();
event.preventDefault();
return;
Expand Down
Loading