mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-07 16:04:19 +01:00
This commit is contained in:
parent
ea378dad16
commit
88e1f0312c
1 changed files with 13 additions and 11 deletions
|
|
@ -297,6 +297,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
return false;
|
||||
}
|
||||
|
||||
const nodeType = nodeElement.getAttribute("data-type");
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.collapse.custom, event) && !event.repeat) {
|
||||
const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
|
||||
if (selectElements.length > 0) {
|
||||
|
|
@ -308,7 +309,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
} else {
|
||||
setFold(protyle, nodeElement);
|
||||
}
|
||||
} else if (nodeElement.getAttribute("data-type") === "NodeHeading") {
|
||||
} else if (nodeType === "NodeHeading") {
|
||||
setFold(protyle, nodeElement);
|
||||
} else {
|
||||
setFold(protyle, getTopAloneElement(nodeElement));
|
||||
|
|
@ -330,7 +331,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
} else {
|
||||
setFold(protyle, nodeElement, true);
|
||||
}
|
||||
} else if (nodeElement.getAttribute("data-type") === "NodeHeading") {
|
||||
} else if (nodeType === "NodeHeading") {
|
||||
setFold(protyle, nodeElement, true);
|
||||
} else {
|
||||
setFold(protyle, getTopAloneElement(nodeElement), true);
|
||||
|
|
@ -634,8 +635,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
}
|
||||
// 需使用 innerText 否则表格内 br 无法传唤为 /n
|
||||
if (event.key === "ArrowDown" && nodeEditableElement?.innerText.trimRight().substr(position.start).indexOf("\n") === -1 && (
|
||||
(tdElement && !tdElement.parentElement.nextElementSibling && nodeElement.getAttribute("data-type") === "NodeTable" && !getNextBlock(nodeElement)) ||
|
||||
(nodeElement.getAttribute("data-type") === "NodeCodeBlock" && !getNextBlock(nodeElement)) ||
|
||||
(tdElement && !tdElement.parentElement.nextElementSibling && nodeType === "NodeTable" && !getNextBlock(nodeElement)) ||
|
||||
(nodeType === "NodeCodeBlock" && !getNextBlock(nodeElement)) ||
|
||||
(nodeElement.parentElement.getAttribute("data-type") === "NodeBlockquote" && nodeElement.nextElementSibling.classList.contains("protyle-attr") && !getNextBlock(nodeElement.parentElement)) ||
|
||||
(nodeElement.parentElement.classList.contains("callout-content") && !nodeElement.nextElementSibling && !getNextBlock(nodeElement.parentElement.parentElement))
|
||||
)) {
|
||||
|
|
@ -900,7 +901,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
} else if (position.end === editElement.innerText.length - 1 && nodeElement.getAttribute("data-type") === "NodeCodeBlock") {
|
||||
} else if (position.end === editElement.innerText.length - 1 && nodeType === "NodeCodeBlock") {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
return;
|
||||
|
|
@ -953,7 +954,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
return;
|
||||
}
|
||||
if (range.startContainer.nodeType !== 3 &&
|
||||
nodeElement.getAttribute("data-type") === "NodeTable" &&
|
||||
nodeType === "NodeTable" &&
|
||||
(range.startContainer as HTMLElement).children[range.startOffset - 1]?.tagName === "TABLE") {
|
||||
nodeElement.classList.add("protyle-wysiwyg--select");
|
||||
removeBlock(protyle, nodeElement, range, "Backspace");
|
||||
|
|
@ -1110,7 +1111,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
}
|
||||
|
||||
// 回车
|
||||
if (matchHotKey("↩", event)) {
|
||||
if (matchHotKey("↩", event) ||
|
||||
(matchHotKey("⇧↩", event) && nodeType === "NodeHeading")) {
|
||||
enter(nodeElement, range, protyle);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
|
@ -1481,7 +1483,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
return true;
|
||||
}
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.insert.code.custom, event) &&
|
||||
!["NodeCodeBlock", "NodeHeading", "NodeTable"].includes(nodeElement.getAttribute("data-type"))) {
|
||||
!["NodeCodeBlock", "NodeHeading", "NodeTable"].includes(nodeType)) {
|
||||
const editElement = getContenteditableElement(nodeElement);
|
||||
if (editElement) {
|
||||
const id = nodeElement.getAttribute("data-node-id");
|
||||
|
|
@ -1560,7 +1562,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
} else if (nodeElement.parentElement.classList.contains("li") && nodeElement.getAttribute("data-type") !== "NodeCodeBlock") {
|
||||
} else if (nodeElement.parentElement.classList.contains("li") && nodeType !== "NodeCodeBlock") {
|
||||
listOutdent(protyle, [nodeElement.parentElement], range);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
|
@ -1586,7 +1588,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
} else if (nodeElement.parentElement.classList.contains("li") && nodeElement.getAttribute("data-type") !== "NodeCodeBlock") {
|
||||
} else if (nodeElement.parentElement.classList.contains("li") && nodeType !== "NodeCodeBlock") {
|
||||
listIndent(protyle, [nodeElement.parentElement], range);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
|
@ -1860,7 +1862,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
if (event.key === "Tab" && isNotCtrl(event) && !event.altKey) {
|
||||
event.preventDefault();
|
||||
const tabSpace = window.siyuan.config.editor.codeTabSpaces === 0 ? "\t" : "".padStart(window.siyuan.config.editor.codeTabSpaces, " ");
|
||||
if (nodeElement.getAttribute("data-type") === "NodeCodeBlock" && selectText !== "") {
|
||||
if (nodeType === "NodeCodeBlock" && selectText !== "") {
|
||||
// https://github.com/siyuan-note/siyuan/issues/12650
|
||||
if (!hasNextSibling(range.endContainer) && range.endContainer.textContent.endsWith("\n") && range.endOffset > 0) {
|
||||
range.setEnd(range.endContainer, range.endOffset - 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue