mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-16 00:50:56 +08:00
This commit is contained in:
parent
11df239bd2
commit
1f918e0773
@ -261,8 +261,9 @@ export const getSelectionOffset = (selectElement: Node, editorElement?: Element,
|
|||||||
preSelectionRange.selectNodeContents(selectElement);
|
preSelectionRange.selectNodeContents(selectElement);
|
||||||
}
|
}
|
||||||
preSelectionRange.setEnd(range.startContainer, range.startOffset);
|
preSelectionRange.setEnd(range.startContainer, range.startOffset);
|
||||||
position.start = preSelectionRange.toString().length;
|
// 需加上表格内软换行 br 的长度
|
||||||
position.end = position.start + range.toString().length;
|
position.start = preSelectionRange.toString().length + preSelectionRange.cloneContents().querySelectorAll("br").length;
|
||||||
|
position.end = position.start + range.toString().length + range.cloneContents().querySelectorAll("br").length;
|
||||||
return position;
|
return position;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import {isNotCtrl} from "./compatibility";
|
|||||||
import {scrollCenter} from "../../util/highlightById";
|
import {scrollCenter} from "../../util/highlightById";
|
||||||
import {insertEmptyBlock} from "../../block/util";
|
import {insertEmptyBlock} from "../../block/util";
|
||||||
import {removeBlock} from "../wysiwyg/remove";
|
import {removeBlock} from "../wysiwyg/remove";
|
||||||
|
import {hasPreviousSibling} from "../wysiwyg/getBlock";
|
||||||
|
|
||||||
const scrollToView = (nodeElement: Element, rowElement: HTMLElement, protyle: IProtyle) => {
|
const scrollToView = (nodeElement: Element, rowElement: HTMLElement, protyle: IProtyle) => {
|
||||||
if (nodeElement.getAttribute("custom-pinthead") === "true") {
|
if (nodeElement.getAttribute("custom-pinthead") === "true") {
|
||||||
@ -463,14 +464,14 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
|
|||||||
const startContainer = range.startContainer as HTMLElement;
|
const startContainer = range.startContainer as HTMLElement;
|
||||||
let previousBrElement;
|
let previousBrElement;
|
||||||
if (startContainer.nodeType !== 3 && (startContainer.tagName === "TH" || startContainer.tagName === "TD")) {
|
if (startContainer.nodeType !== 3 && (startContainer.tagName === "TH" || startContainer.tagName === "TD")) {
|
||||||
previousBrElement = (startContainer.childNodes[Math.max(0, range.startOffset - 1)] as HTMLElement)?.previousElementSibling;
|
previousBrElement = (startContainer.childNodes[Math.min(range.startOffset, startContainer.childNodes.length - 1)] as HTMLElement);
|
||||||
} else if (startContainer.parentElement.tagName === "SPAN") {
|
} else if (startContainer.parentElement.tagName === "SPAN") {
|
||||||
previousBrElement = startContainer.parentElement.previousElementSibling;
|
previousBrElement = startContainer.parentElement.previousElementSibling;
|
||||||
} else {
|
} else {
|
||||||
previousBrElement = startContainer.previousElementSibling;
|
previousBrElement = startContainer.previousElementSibling;
|
||||||
}
|
}
|
||||||
while (previousBrElement) {
|
while (previousBrElement) {
|
||||||
if (previousBrElement.tagName === "BR") {
|
if (previousBrElement.tagName === "BR" && hasPreviousSibling(previousBrElement)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
previousBrElement = previousBrElement.previousElementSibling;
|
previousBrElement = previousBrElement.previousElementSibling;
|
||||||
|
@ -622,7 +622,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||||||
const tdElement = hasClosestByMatchTag(range.startContainer, "TD") || hasClosestByMatchTag(range.startContainer, "TH");
|
const tdElement = hasClosestByMatchTag(range.startContainer, "TD") || hasClosestByMatchTag(range.startContainer, "TH");
|
||||||
const nodeEditableElement = (tdElement || getContenteditableElement(nodeElement) || nodeElement) as HTMLElement;
|
const nodeEditableElement = (tdElement || getContenteditableElement(nodeElement) || nodeElement) as HTMLElement;
|
||||||
const position = getSelectionOffset(nodeEditableElement, protyle.wysiwyg.element, range);
|
const position = getSelectionOffset(nodeEditableElement, protyle.wysiwyg.element, range);
|
||||||
if (event.key === "ArrowDown" && nodeEditableElement?.textContent.trimRight().substr(position.start).indexOf("\n") === -1 && (
|
// 需使用 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)) ||
|
(tdElement && !tdElement.parentElement.nextElementSibling && nodeElement.getAttribute("data-type") === "NodeTable" && !getNextBlock(nodeElement)) ||
|
||||||
(nodeElement.getAttribute("data-type") === "NodeCodeBlock" && !getNextBlock(nodeElement)) ||
|
(nodeElement.getAttribute("data-type") === "NodeCodeBlock" && !getNextBlock(nodeElement)) ||
|
||||||
(nodeElement.parentElement.getAttribute("data-type") === "NodeBlockquote" && nodeElement.nextElementSibling.classList.contains("protyle-attr") && !getNextBlock(nodeElement.parentElement))
|
(nodeElement.parentElement.getAttribute("data-type") === "NodeBlockquote" && nodeElement.nextElementSibling.classList.contains("protyle-attr") && !getNextBlock(nodeElement.parentElement))
|
||||||
@ -697,7 +698,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.key === "ArrowDown") {
|
if (event.key === "ArrowDown") {
|
||||||
if (nodeEditableElement?.textContent.trimRight().substr(position.start).indexOf("\n") === -1 &&
|
if (nodeEditableElement?.innerText.trimRight().substr(position.start).indexOf("\n") === -1 &&
|
||||||
nodeElement.isSameNode(protyle.wysiwyg.element.lastElementChild)) {
|
nodeElement.isSameNode(protyle.wysiwyg.element.lastElementChild)) {
|
||||||
setLastNodeRange(getContenteditableElement(nodeEditableElement), range, false);
|
setLastNodeRange(getContenteditableElement(nodeEditableElement), range, false);
|
||||||
range.collapse(false);
|
range.collapse(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user